comparing date time

C

Chris Croughton

Not always.
string("31/12/2004 23:59") > string("01/01/2005 00:00") (lexicographically)

If the year is the same in both, what you say is true.

No, only if both the year and the month are the same.

string("31/01/2004 23:59") > string("01/02/2004 00:00") (lexicographically)

That's why ISO 8601 is better, because everything proceeds left to right
as the significance is less, just as in numeric formats (excluding
things like Roman numerals!):

string("2004-01-31 23:59") < string("2004-02-01 00:00") (lexicographically)

which is correct for all values of date.

Chris C
 
H

Howard

Javier said:
Hi

I4ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20


In some moment I4ll need to check if there are in vector a date like
current date with a time >= current time and <= (current time + n minutes)

I4m new to C++ but, nevertheless, I know how to search in a vector, but
how could I make date time comparisons ?



Thanks in advance

J


PD: I4m working with VC++ 6

If you're working with VC++, and if you don't care about the software being
portable to other systems, then you can use the VC++ libraries that provide
date-time conversion routines. Given a specific representation, they will
convert that string to a data structure with the day,month, year,hour, etc.
all filled out. (I think it's call CDateTime, but I'm not sure.) You can
then do your comparison using the values from those structures. That's
easier that parsing the strings yourself. But as I said, it's specific to
VC++ (and Windows?), so you'd need to read their doc's or check on a vc++
newsgroup for more specifics.

-Howard
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top