CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2001
    Location
    India
    Posts
    145

    Question 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

  2. #2
    Join Date
    May 2002
    Posts
    10
    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);
    }

  3. #3
    Join Date
    Oct 2001
    Location
    India
    Posts
    145

    Thumbs up

    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
  •  





Click Here to Expand Forum to Full Width

Featured