Re: Help needed with working with dates

Discussion in 'C++' started by TreatmentPlant, Apr 26, 2006.

  1. Ulrich Eckhardt wrote:
    > TreatmentPlant wrote:
    >> I am having a lot of trouble trying to work with dates.
    >>
    >> I am looking for a simple script to return true if the date today is
    >> after a particular date, say 27 April 2006, false otherwise.
    >>
    >> I know this is a simple request, but none of my books have anything
    >> dealing with dates, and Google isn't doing too much for me either?

    >
    > If you have the date in a string like "27 April 2006", you can split it up
    > in three numbers ("April" will have to become 4).
    > You can then say:
    > 1. If the year of today is greater than the year, it is after today.
    > 2. If the year of today is smaller, then it is before today
    > 3. If neither is true, i.e. the years are equal, you need to look at the
    > months where the same principle of ordering applies.
    >
    > Otherwise I would have a look at Boost's DateTime library.
    >
    > Uli
    >

    POSTED AT:
    alt.comp.lang.learn.c-c++
    comp.lang.c++

    Surely I don't have to go to Boost and get 10MB of header files just to
    solve this problem!! That seems incredible.

    It is such a really simple problem... all I want to do is compare two
    dates, one is today and the other is a hard coded date. Nothing in any
    of my books shows me how to do it. All the sites I have visited are
    trying to show me how to make timers, stopwatches etc.

    I just want to programmatic way to find if today's date is before or
    after a specified date. 27 April 2006 was just an example.

    Please help.
     
    TreatmentPlant, Apr 26, 2006
    #1
    1. Advertisements

  2. TreatmentPlant wrote:
    > Ulrich Eckhardt wrote:
    >> TreatmentPlant wrote:
    >>> I am having a lot of trouble trying to work with dates.
    >>>
    >>> I am looking for a simple script to return true if the date today is
    >>> after a particular date, say 27 April 2006, false otherwise.
    >>>
    >>> I know this is a simple request, but none of my books have anything
    >>> dealing with dates, and Google isn't doing too much for me either?

    >>
    >> If you have the date in a string like "27 April 2006", you can split
    >> it up
    >> in three numbers ("April" will have to become 4). You can then say: 1.
    >> If the year of today is greater than the year, it is after today.
    >> 2. If the year of today is smaller, then it is before today
    >> 3. If neither is true, i.e. the years are equal, you need to look at the
    >> months where the same principle of ordering applies.
    >>
    >> Otherwise I would have a look at Boost's DateTime library.
    >>
    >> Uli
    >>

    > POSTED AT:
    > alt.comp.lang.learn.c-c++
    > comp.lang.c++
    >
    > Surely I don't have to go to Boost and get 10MB of header files just to
    > solve this problem!! That seems incredible.
    >
    > It is such a really simple problem... all I want to do is compare two
    > dates, one is today and the other is a hard coded date. Nothing in any
    > of my books shows me how to do it. All the sites I have visited are
    > trying to show me how to make timers, stopwatches etc.
    >
    > I just want to programmatic way to find if today's date is before or
    > after a specified date. 27 April 2006 was just an example.
    >
    > Please help.



    P.S. This is required for a non-MFC dll file so I cannot use CTime and
    COleTimeDate ahich are in afx.h and afxdisp.h
     
    TreatmentPlant, Apr 26, 2006
    #2
    1. Advertisements

  3. TreatmentPlant

    Guest

    > > TreatmentPlant wrote:
    > >> I am having a lot of trouble trying to work with dates.


    > It is such a really simple problem... all I want to do is compare two
    > dates, one is today and the other is a hard coded date. Nothing in any
    > of my books shows me how to do it. All the sites I have visited are
    > trying to show me how to make timers, stopwatches etc.


    Convert both to time_t format (using midnight on the hardcoded date).
    You can compare those as if they are int's.

    HTH,
    Michiel Salters
     
    , Apr 26, 2006
    #3
  4. TreatmentPlant wrote:
    > Ulrich Eckhardt wrote:
    >> TreatmentPlant wrote:
    >>> I am having a lot of trouble trying to work with dates.
    >>>
    >>> I am looking for a simple script to return true if the date today is
    >>> after a particular date, say 27 April 2006, false otherwise.
    >>>
    >>> I know this is a simple request, but none of my books have anything
    >>> dealing with dates, and Google isn't doing too much for me either?

    >>
    >> If you have the date in a string like "27 April 2006", you can split
    >> it up
    >> in three numbers ("April" will have to become 4). You can then say: 1.
    >> If the year of today is greater than the year, it is after today.
    >> 2. If the year of today is smaller, then it is before today
    >> 3. If neither is true, i.e. the years are equal, you need to look at the
    >> months where the same principle of ordering applies.
    >>
    >> Otherwise I would have a look at Boost's DateTime library.
    >>
    >> Uli
    >>

    > POSTED AT:
    > alt.comp.lang.learn.c-c++
    > comp.lang.c++
    >
    > Surely I don't have to go to Boost and get 10MB of header files just to
    > solve this problem!! That seems incredible.
    >
    > It is such a really simple problem... all I want to do is compare two
    > dates, one is today and the other is a hard coded date. Nothing in any
    > of my books shows me how to do it. All the sites I have visited are
    > trying to show me how to make timers, stopwatches etc.
    >
    > I just want to programmatic way to find if today's date is before or
    > after a specified date. 27 April 2006 was just an example.
    >
    > Please help.


    Thanks to all those that offered assistance.
    I have the problem sorted out now.

    It seems that when you use struct tm , you need to provide ALL the
    values for the time and date, when the documentation I have says you
    don't need to!

    Thanks again!
     
    TreatmentPlant, Apr 27, 2006
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Justin Dutoit

    Working with Dates in VB.NET

    Justin Dutoit, Jan 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,659
    Kevin Spencer
    Jan 28, 2004
  2. xenophon
    Replies:
    2
    Views:
    536
    Steven Cheng[MSFT]
    May 11, 2005
  3. David Lozzi

    Dates dates dates dates... SQL and ASP.NET

    David Lozzi, Sep 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,080
    Rob Schieber
    Sep 30, 2005
  4. PW

    Dates! Dates! Dates!

    PW, Aug 7, 2004, in forum: ASP General
    Replies:
    4
    Views:
    494
    Mark Schupp
    Aug 9, 2004
  5. Ryan Macy

    Ideas needed & help needed!

    Ryan Macy, Jul 19, 2006, in forum: Ruby
    Replies:
    2
    Views:
    705
    Ryan Macy
    Jul 19, 2006
  6. Replies:
    1
    Views:
    381
    Jano Svitok
    Jul 17, 2007
  7. kellygreer1

    RFC-822 dates into Ruby dates

    kellygreer1, Jun 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    466
    Eric I.
    Jun 8, 2008
  8. Dr J R Stockton

    FAQ Dates; Opera Dates.

    Dr J R Stockton, Jun 18, 2007, in forum: Javascript
    Replies:
    0
    Views:
    309
    Dr J R Stockton
    Jun 18, 2007
Loading...