Link to home
Start Free TrialLog in
Avatar of arichexe
arichexe

asked on

today's date minus 7 days

How would I write a C function that returns today's date minus 7 days?  For instance, if today's date was 11/13/2006, it would return 11/6/2006.
Avatar of sunnycoder
sunnycoder
Flag of India image

Hi arichexe,

time() would give you current time in seconds since epoch ...
Subtract 7 * 24 * 3600 from this value ... this would give you time 7 days ago ...
To get other representations of this time, use ctime/ctime_r etc

time_t val = time (NULL);
val = val - (7 * 24 * 3600);
printf ("%s",ctime(&val));

Cheers!
sunnycoder
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial