473,388 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

comparing date time


Hi

I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20
In some moment I´ll need to check if there are in vector a date like
current date with a time >= current time and <= (current time + n minutes)

I´m 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: I´m working with VC++ 6
Jul 23 '05 #1
21 11013
"Javier" writes:
I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20


Not to change the subject but where on this planet is such a time
representation used and valid?
Jul 23 '05 #2
osmium wrote:
"Javier" writes:

I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20

Not to change the subject but where on this planet is such a time
representation used and valid?

I've seen that ordering, but not with that punctuation in the Military
and frequently in Europe.
Jul 23 '05 #3
"Ron Natalie" writes:
osmium wrote:
"Javier" writes:

I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20

Not to change the subject but where on this planet is such a time
representation used and valid?

I've seen that ordering, but not with that punctuation in the Military
and frequently in Europe.


It sure looks like February 30th to me.
Jul 23 '05 #4
osmium wrote:
30/02/2005 19:20

Not to change the subject but where on this planet is such a time
representation used and valid?

What exactly do you think is invalid? In Europe dates are in the form
dd/mm/yyyy or dd/mm/yy.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5
Ioannis Vranos wrote:
30/02/2005 19:20


Not to change the subject but where on this planet is such a time
representation used and valid?


What exactly do you think is invalid? In Europe dates are in the form
dd/mm/yyyy or dd/mm/yy.


.... and time is used in both 12h/24h formats.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #6
osmium wrote:

"Ron Natalie" writes:
osmium wrote:
"Javier" writes:
I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20
Not to change the subject but where on this planet is such a time
representation used and valid?

I've seen that ordering, but not with that punctuation in the Military
and frequently in Europe.


It sure looks like February 30th to me.


C'mon. The OP was simply typing an example without thinking and made a
mistake in the values. That doesn't change his problem.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #7
Ioannis Vranos wrote:
What exactly do you think is invalid? In Europe dates are in the form
dd/mm/yyyy or dd/mm/yy.

... and time is used in both 12h/24h formats.

I just realised the OP's 30th of February...


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #8
osmium wrote:
"Javier" writes:

I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20

Not to change the subject but where on this planet is such a time
representation used and valid?

How much of this planet do you know ?

In Europe and all South America, people use to represent dates in that
way: dd/mm/yyyy. May be you need to make a trip through the 99,99% of
the world you unknown... :)

In this case, this data comes from a Visual Fox application and is
stored in that way in a MSDE.

J

Jul 23 '05 #9
On Mon, 21 Feb 2005 09:06:35 -0500, Ron Natalie
<ro*@sensor.com> wrote:
osmium wrote:
"Javier" writes:
I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20


Not to change the subject but where on this planet is such a time
representation used and valid?

I've seen that ordering, but not with that punctuation in the Military
and frequently in Europe.


Military time is normally ISO 8601 now (yyyy.mm.ddThh:mm:ss, with optional
separators). Normal UK date notation is dd/mm/yyyy (continental Europe
tends to use dd.mm.yyyy, using - as separator is also common; prior to
2000 the year was often 2 digits instead of 4 (and sometimes still is
that way). Only the UK and dependencies now generally use the 12-hour
clock, a lot of European languages don't even have a concept of AM and
PM, and most public bodies in the UK now use 24-hour (buses, trains,
etc.).

(Of course, none of them actually use the 30th of February in any year,
but it was the representation which was being queried not the value...)

Chris C
Jul 23 '05 #10
"Javier" writes:
osmium wrote:
"Javier" writes:

I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20

Not to change the subject but where on this planet is such a time
representation used and valid?

How much of this planet do you know ?


Does the word "valid" have any meaning at all to you?
Jul 23 '05 #11
On Mon, 21 Feb 2005 13:29:19 -0800, osmium
<r1********@comcast.net> wrote:
"Javier" writes:
osmium wrote:
"Javier" writes:

I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20

Not to change the subject but where on this planet is such a time
representation used and valid?


How much of this planet do you know ?


Does the word "valid" have any meaning at all to you?


You said "time representation", that representation is valid. The date
itself is not valid, but that's not what you asked...

Chris C
Jul 23 '05 #12
Javier wrote:

Hi

I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20

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

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


To get back to the question asked:
In order to compare such dates, you will need to split the complete string
into pieces and compare those pieces. This gets simple, if the format of
the time string is constant and always the same.

Search out for string manipulation functions, especially on how to get
a substring from a string. The other thing that will be handy, is a function
which converts a string representation of a number into a number.

Once you have all those pieces (day, month, year, hour, minute) as numbers,
comparing them should not be a problem. When you do your tests, make sure you
also test the cases, where the time intervall crosses midnight :-)

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #13
Javier wrote:

Hi

I´ve a routine that will read date and times in a vector of strings ie:

30/02/2005 19:20
In some moment I´ll need to check if there are in vector a date like
current date with a time >= current time and <= (current time + n minutes)

I´m 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: I´m working with VC++ 6


Now, I bet you didn't expect to kick off a flame war about time
formatting with this topic did you? :D

As to your problem:
I think it would be a better idea to have your date/time being
represented by some class than by plain strings, so you can compare
using operator==. I haven't worked with it, but I suggest you have a
look at boost::date_time
http://www.boost.org/libs/date_time/doc/index.html

Maybe they have what you need.

--
Matthias Kaeppler
Jul 23 '05 #14
Chris Croughton wrote:
Military time is normally ISO 8601 now (yyyy.mm.ddThh:mm:ss, with optional
separators). Normal UK date notation is dd/mm/yyyy (continental Europe
tends to use dd.mm.yyyy, using - as separator is also common; prior to
2000 the year was often 2 digits instead of 4 (and sometimes still is
that way). Only the UK and dependencies now generally use the 12-hour
clock, a lot of European languages don't even have a concept of AM and
PM, and most public bodies in the UK now use 24-hour (buses, trains,
etc.).


Another benefit of using ISO8601 time is that comparison is reduced to
plain old string comparison. The documentation of ISO8601 time that I
have seen uses "-" instead of ".": yyyy-mm-ddThh:mm:ss.
Jul 23 '05 #15
On Tue, 22 Feb 2005 08:51:48 -0500, Eric Sokolowsky
<es***@hotmail.com> wrote:
Chris Croughton wrote:
Military time is normally ISO 8601 now (yyyy.mm.ddThh:mm:ss, with optional
separators). Normal UK date notation is dd/mm/yyyy (continental Europe
tends to use dd.mm.yyyy, using - as separator is also common; prior to
2000 the year was often 2 digits instead of 4 (and sometimes still is
that way). Only the UK and dependencies now generally use the 12-hour
clock, a lot of European languages don't even have a concept of AM and
PM, and most public bodies in the UK now use 24-hour (buses, trains,
etc.).


Another benefit of using ISO8601 time is that comparison is reduced to
plain old string comparison. The documentation of ISO8601 time that I
have seen uses "-" instead of ".": yyyy-mm-ddThh:mm:ss.


You're right, I was thinking of the continental version when I typed
that bit (actually, I typed it without separators and then added them,
and added the wrong ones). Having it comparable with a string
comparison makes things very easy.

Chris C
Jul 23 '05 #16
Chris Croughton wrote:
You're right, I was thinking of the continental version when I typed
that bit (actually, I typed it without separators and then added them,
and added the wrong ones). Having it comparable with a string
comparison makes things very easy.

My first thought is that the default std::string comparison operators
will do the job (lexicographical comparison), so if we have
string("27/02/2005 19:20") < string("28/02/2005 19:20")
will always be true as also
string("27/02/2005 19:19") < string("27/02/2005 19:20").
So the only thing needed, is the input to be checked whether it is in
the correct string format for the program (here "dd/mm/yyyy' 'hh:mm").


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #17

"Ioannis Vranos" <iv*@remove.this.grad.com>, haber iletisinde sunlari
yazdi:1109086397.376682@athnrd02...
string("27/02/2005 19:20") < string("28/02/2005 19:20")
will always be true as also
string("27/02/2005 19:19") < string("27/02/2005 19:20").

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.
Jul 23 '05 #18
Aslan Kral wrote:
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.

string("2004/31/12 23:59") < string("2005/01/01 00:00")
makes the implementation simpler then. :-)


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #19
Ioannis Vranos wrote:
string("2004/31/12 23:59") < string("2005/01/01 00:00")
makes the implementation simpler then. :-)

I meant yyyy/mm/dd hh:mm :

string("2004/12/31 23:59") < string("2005/01/01 00:00")


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #20
On Tue, 22 Feb 2005 17:56:13 +0200, Aslan Kral
<as**********@yahoo.com> wrote:
"Ioannis Vranos" <iv*@remove.this.grad.com>, haber iletisinde sunlari
yazdi:1109086397.376682@athnrd02...
string("27/02/2005 19:20") < string("28/02/2005 19:20")
will always be true as also
string("27/02/2005 19:19") < string("27/02/2005 19:20").

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
Jul 23 '05 #21

"Javier" <jl****@manresa.net> wrote in message
news:cv**********@news.ya.com...

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


Jul 23 '05 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: teddysnips | last post by:
I have a table called WorkItem. It models a chunk of work done during a working day. It has two columns that I'm interested in: Start (smalldatetime) - the TIME the work block is begun...
2
by: Philip Townsend | last post by:
I am having difficulty with a simple routine as follows: public static bool VerifyExpirationDate(DateTime date) { if(date>=DateTime.Now)return true; else return false; } The problem is that...
4
by: richardkreidl | last post by:
How would I check to see if the current time(military format) is greater then 07:30AM and the day of the week is Monday-Friday. Pseudo code: If Current_Time > 07:30AM and Current_Day = Monday...
5
by: Kermit Piper | last post by:
Hello, I am comparing two date values, one from a database and one that has been converted from a hard-coded string into an actual Date type. So far so good. The problem I'm having is that one...
12
by: colincolehour | last post by:
I am new to Python and am working on my first program. I am trying to compare a date I found on a website to todays date. The problem I have is the website only shows 3 letter month name and the...
2
by: Bob | last post by:
Hi, I have a wrong result when testing today against a date fetched from a table in excel. The value in excel is: 14/12/2006 (european format). When today is after that value in excel, the...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
4
by: anagai | last post by:
I just want to check if a date entered in a textbox is equal to the current system date. I set the date object from the input field like this: dt1=new Date('10/01/2007'); the current system...
2
hodgeman
by: hodgeman | last post by:
My second thread on thescripts, so hoping to get the same feedback and help as last time... I've developed an online invoicing and payment system for all my accounts for my web design company....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.