#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Istanbul, TR
    Posts
    85
    Rep Power
    12

    time comparison in C


    I want to deploy files which are modified after a given date.
    I have done much of it. But cant compare two times

    i first get the files' modified time with stat structure..
    and get the user's date input..

    how can i do the comparison

    if ( user_date < file_modified_time) {

    ........................
    }

    thanks for your advice.
  2. #2
  3. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    12
    this is just a suggestion. you could try making numbers using the date and time in this format:

    YYYYMMDDHHmmSS

    so like this for example :

    20030807021945 (that's 2:19.45 am 7th Aug 2002)

    so the largest thing always goes on the left - just like normal numbers. that way you can then compare them and they're to a certain extent human readable or fairly easily human decypherable at least, if that's an issue.

    or you could make use of the time format that's on most computers i think that gives the number of seconds since 1970 (it's not such a large number than you might think). i think that format is available from the time() function

    #include <time.h>

    see about time in your manual. on my machine it's:
    man 3 time
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Istanbul, TR
    Posts
    85
    Rep Power
    12

    strftime


    You are right i wrote it like below.. thanks for your help.

    char * get_mtime(time_t mytime) {

    struct tm *time_struct;
    static char buff[10];

    time_struct=localtime(&mytime);

    strftime(buff, sizeof buff, "%Y%m%d\n", time_struct);

    return(buff);
    }

IMN logo majestic logo threadwatch logo seochat tools logo