String Comparing
-
I am working for an application where i am supposed to display the latest data on a list box from a XML. I got the datetime node from the XML and saved it into a string. which is the format of str = "2009/12/3|19:04:43" & str1 = "2009/12/3|19:05:23" My only concern is how is it possible to compare these two strings by date & time and display the one which is latest. Please let me know the simplest way to compare them. Thanks in Advance
-
I am working for an application where i am supposed to display the latest data on a list box from a XML. I got the datetime node from the XML and saved it into a string. which is the format of str = "2009/12/3|19:04:43" & str1 = "2009/12/3|19:05:23" My only concern is how is it possible to compare these two strings by date & time and display the one which is latest. Please let me know the simplest way to compare them. Thanks in Advance
You could use the COleDateTime::ParseDateTime[^] function in order to "convert" the strings into COleDateTime objects which are comparable. But your string has to be a standard format. Is the format in the xml fixed or could you adapt it a bit ? In yes, then I would suggest to use a standard format and then use COleDateTime objects.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
I am working for an application where i am supposed to display the latest data on a list box from a XML. I got the datetime node from the XML and saved it into a string. which is the format of str = "2009/12/3|19:04:43" & str1 = "2009/12/3|19:05:23" My only concern is how is it possible to compare these two strings by date & time and display the one which is latest. Please let me know the simplest way to compare them. Thanks in Advance
Looks like your strings are in year/month/day|hour:min:sec format. The 19 hour indicates you are using 24 hr notation (rather than 12 hr + am/pm) - good. The only change you need to make is format your day as 03 instead of 3. After that why can't you just do a normal string compare ?
...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack
-
You could use the COleDateTime::ParseDateTime[^] function in order to "convert" the strings into COleDateTime objects which are comparable. But your string has to be a standard format. Is the format in the xml fixed or could you adapt it a bit ? In yes, then I would suggest to use a standard format and then use COleDateTime objects.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Looks like your strings are in year/month/day|hour:min:sec format. The 19 hour indicates you are using 24 hr notation (rather than 12 hr + am/pm) - good. The only change you need to make is format your day as 03 instead of 3. After that why can't you just do a normal string compare ?
...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack
Normal string comparison can be done however if the values of the strings are changed to str = "2009/12/3|19:04:43" & str1 = "2009/12/3|9:05:23" Then It shows that str1 is greater than str though STRING str is the latest one. Thus i want to have other way where we can compare them by date and time.
-
No we are not supposed to change the format. I will be happy if you could provide me the sample code for parsing the date & time from the string and do the comparision. Thanks in advance
-
I am working for an application where i am supposed to display the latest data on a list box from a XML. I got the datetime node from the XML and saved it into a string. which is the format of str = "2009/12/3|19:04:43" & str1 = "2009/12/3|19:05:23" My only concern is how is it possible to compare these two strings by date & time and display the one which is latest. Please let me know the simplest way to compare them. Thanks in Advance
If you cannot change the format and want to know the difference, then extract year and compare first. If they are same, extract month and compare. Continue this for day, hour, minute and second. You can extract by tokenizing the string using the tokens /|: Or you can simply delete the 3 charecters from the string /|: And then assign them to
ULONGLONG
variables and compare the numbers.«_Superman_»
-
Normal string comparison can be done however if the values of the strings are changed to str = "2009/12/3|19:04:43" & str1 = "2009/12/3|9:05:23" Then It shows that str1 is greater than str though STRING str is the latest one. Thus i want to have other way where we can compare them by date and time.
That's not the same as the original you showed. In your op both were 19: which made me assume you were using 2 digit formatting for everything but day, which is why i said change it. You said you are saving the string so i assume you control the formatting. Just use YYYY/MM/DD|hh:mm:ss and you'll be fine. So for your last example you'd have: str = "2009/12/03|19:04:43" str1 = "2009/12/03|09:05:23"
...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack