PDA

View Full Version : How to Compare two QString in the form of QDateTime ?



George Neil
1st March 2010, 05:51
I am using QT 4.5.0

I need to compare two QString which are in the following format.

MM/DD/YYYY hh:mm:ss

where MM,DD,YYYY stands for Month, Date, Year and hh,mm,ss stands for hour,min,sec.

I tried the following steps

1) Split the QSting w.r.t " " [ blank space]

2) Compare w.r.t the Date part / Time part.

I want to know is there any simple method other than the above 2 step method ?

abghosh
1st March 2010, 06:00
I am using QT 4.5.0

I need to compare two QString which are in the following format.

MM/DD/YYYY hh:mm:ss

where MM,DD,YYYY stands for Month, Date, Year and hh,mm,ss stands for hour,min,sec.

I tried the following steps

1) Split the QSting w.r.t " " [ blank space]

2) Compare w.r.t the Date part / Time part.

I want to know is there any simple method other than the above 2 step method ?


If both of your strings are in the same format as mentioned then you can convert then to date e.g.


QDateTime::fromString("10/10/2008 10:15 Am", "dd/MM/yyyy hh:mm ap")

and then compare them.

George Neil
1st March 2010, 06:24
Okay, In my case there are also chances for different date/time formats. So how to find the Date time format from a given QString.

Whats the best / easy method ?

abghosh
1st March 2010, 06:27
Okay, then How to find the Date time format from a given QString.

Whats the best / easy method ?

You have a known string format?

George Neil
1st March 2010, 06:57
No, there are chances for different date/time formats in the string, like M/D/YYYY OR MM/DD/YYYY