Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Help needed with working with dates

Reply
Thread Tools

Re: Help needed with working with dates

 
 
TreatmentPlant
Guest
Posts: n/a
 
      04-26-2006
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.
 
Reply With Quote
 
 
 
 
TreatmentPlant
Guest
Posts: n/a
 
      04-26-2006
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
 
Reply With Quote
 
 
 
 
Michiel.Salters@tomtom.com
Guest
Posts: n/a
 
      04-26-2006
> > 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

 
Reply With Quote
 
TreatmentPlant
Guest
Posts: n/a
 
      04-27-2006
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RFC-822 dates into Ruby dates kellygreer1 Ruby 1 06-08-2008 10:59 PM
Need to use dates earlier than 1900 (Time library says out of range for dates < 1900) me@benjaminarai.com Ruby 1 07-17-2007 02:25 PM
FAQ Dates; Opera Dates. Dr J R Stockton Javascript 0 06-18-2007 03:51 PM
Dates dates dates dates... SQL and ASP.NET David Lozzi ASP .Net 1 09-30-2005 02:18 PM
Dates! Dates! Dates! PW ASP General 4 08-09-2004 04:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57