Thread: compasion of dates

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    90

    compasion of dates

    how can i compare 2 days
    example
    date1=22:06:2007;
    date2=23:06:2007;
    how can i compare two dates
    thank u
    sree

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    See the functions in time.h. Here's what the FAQ from this site says about dates and times:

    http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    BTW, you're talking about the comparison of two dates.... compassion has a meaning related to love, mercy, and perhaps pity.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    90
    thank u for u r reply
    i already seen tht tutorial.
    but i didn't found any function for date.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You should look slightly closer at it since you should be able to do what you want with the functions in time.h. I would also suggest you search the forums since this subject has come up before.

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    90
    i searched the forum i didn't get any help.
    i tried like this
    struct tm ctime,ptime;
    int y,m,d,y1,m1,d1;
    sscanf("23:06:2007", "%od:%od:%od", &y, &m, &d);
    ctime.tm_year=y;
    ctime.tm_mday=d;
    ctime.tm_mon=m;
    sscanf("22:06:2007", "%od:%od:%od", &y1, &m1, &d1);
    ptime.tm_year=y1;
    ptime.tm_mday=d1;
    ptime.tm_mon=m1;
    time_t now1,now2;
    now1=mktime(&ctime);
    now2=mktime(&ptime);
    g_print("***************** %d \n",difftime(now2,now1));


    but it's output is "0".
    thanks

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    %od isn't a valid scanf format.
    %d isn't a valid format for printing a floating point value.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    90
    thank u
    so please tell me wht should i do.
    with what character i should replace "%0d"

  8. #8
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    with a "%d". I just hope your teacher didnt teach u to put a " 0 " there.
    In the middle of difficulty, lies opportunity

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    90
    yah i know .
    but can u tell me how we can compare dates

  10. #10
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Well, using the difftime would u cant compare dates. It will return values in seconds. Which is not useful is it?

    What u can go is, you can compare each values manually.

    ssharish2005

  11. #11
    Registered User
    Join Date
    Aug 2006
    Posts
    90
    ok thank u for ur replyyy

  12. #12
    Registered User
    Join Date
    Jan 2007
    Posts
    72
    take the years months and days as separated items. then, compare first the years and if they are similar then months then the days
    proud to be from aui www.aui.ma and also a great elton john's fan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting days between 2 dates
    By nynicue in forum C Programming
    Replies: 12
    Last Post: 02-19-2010, 10:50 AM
  2. Generating Dates! Compiles but does not work...
    By ottomated in forum C Programming
    Replies: 11
    Last Post: 04-22-2008, 03:58 AM
  3. Getting the difference between dates
    By Leftos in forum C Programming
    Replies: 7
    Last Post: 01-20-2008, 12:49 AM
  4. Using dates in Pro*C
    By clancyPC in forum C Programming
    Replies: 0
    Last Post: 08-17-2006, 06:37 AM
  5. Comparing Dates?
    By Excalibur XP in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 09:00 PM