|
-
May 27th, 2002, 07:23 AM
#1
Adding days to a Date
hi,
I need to write a set of utility functions for my comapny and i am really lft with lil time, i jsut thougth that if someone can help or have the source code for a particular function, which adds the given number of days to a date .
thanx
Muthu
-
May 27th, 2002, 09:36 AM
#2
You can triy this:
#include <time.h>
struct tm * AddDays(struct tm* day,int nb)
{
long sec = 0;
time_t aday_t;
if(day == NULL)
return NULL;
if(nb < 0)
nb = 1;
sec = nb*24*60*60;
if((aday_t = mktime(day)) == -1)
return NULL;
aday_t += sec;
return gmtime(&aday_t);
}
void main(void)
{
struct tm *aday,*nextday;
time_t tim;
time(&tim);
aday = localtime(&tim);
nextday = AddDays(aday,4);
}
-
May 28th, 2002, 01:38 AM
#3
hey, that was a cool piece of code, i was thinking abt, chacking if bigger than 30 and blah blah blah stuff, this made it neat, thanx man.
regards
Muthu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|