Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need to manipulate date in my c program. I'm using SYSTEMTIME to get the current date. How can i get the yesterday's date. I can subtract 1 to the day but for first day of the month it will not work out. Is there any workaround for this. Any help is appreciated.

I don't remember the exact function, but the lowest level time function returns the system time in seconds since some base date (usually Jan 1, 1970).
So if you use that function, then subtract NumberOfSecondsInADay, you'll have the current time minus one day. Then you'll need to pass that value into the higher functions.
I did a quick glance at man pages and it looks like:
time() returns the time in seconds (use "man 2 time" for docs)
ctime(), gmtime(), localtime() can use the seconds value as input to make it meaningful to you (man ctime)

Well honestly ive never bothered about what
day it is :), but i suppose there are
ways to get around this.
I suppose that SYSTEMTIME also tells what
month it is, so you can make a list that
tells how many days a month has.
For example, if its 1 JUN,
yesterdays date is 31 MAY. If its 1 MAY,
yesterdays date is 30 APR. And ofcourse you
have to take into consideration that every
fourth year FEB only got 27 days (or what
ever, how should i know! ). Now as i sed
ive never needed to know what date there is
in my programs, so you will have to figure
some code out. Use your imagenation!!!

Hi -
/* This works on 32 bit machines, perhaps not on a 64 bit one */
time_t tta, ttb;
tta = time(NULL); /* right now */
printf("%s", ctime(&tta));
ttb = tta - 24*60*60; /* minus seconds in a day */
printf("%s", ctime(&ttb));HTH, Guy

![]() |
Which is faster in perfor...
|
Vb easy question
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |