Thread: how do i compare dates

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    2

    how do i compare dates

    Hi guys,
    Can anybody help me in knowing the date related functions in C or C++ using win 32.
    I want to compare 2 dates and also do some operations on the date value like adding days and months .
    Kindly help me


    Saif

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Write a date class, storing month,day,year as ints. ie

    Code:
    class date
    {
          int m, d, y;
    public:
          date() : m(0),d(0),y(0) {}
          date(int M, int D, int Y) : m(M), d(D), y(Y) { }
          date(const date& dt) { m = dt.m; d = dt.d; y = dt.y; }
          
          int month() const { return m; }
          int day() const { return d; }
          int year() const { return y; }
    
    };
    Then you could write some operators and, uh... stuff ... =)
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Are you using Windows? If so there are some helpful functions to aid the process. Using GetLocalTime() or GetSystemTime() and SystemTimeToFileTime() with FileTimeToSystemTime() can produce accurate dates in the form or 64-bit integers. The one major problem (in C/C++ anyway) is that there is no native support for doing 64-bit math. Your options are assembler or writing a couple of functions for doing some 64-bit addition and subtraction. Either way it is actually much easier than only using a class that maintains the date.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting the difference between dates
    By Leftos in forum C Programming
    Replies: 7
    Last Post: 01-20-2008, 12:49 AM
  2. compasion of dates
    By cnu_sree in forum C Programming
    Replies: 11
    Last Post: 07-08-2007, 05:34 PM
  3. compare strings not working
    By gtriarhos in forum C Programming
    Replies: 7
    Last Post: 09-29-2005, 12:51 PM
  4. Help Writing My Own String Compare
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 04-07-2005, 09:44 PM
  5. String Compare Using Dynamic Arrays
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 03-31-2005, 08:01 PM