Results 1 to 5 of 5

Thread: How to Compare two QString in the form of QDateTime ?

  1. #1
    Join Date
    Jun 2008
    Posts
    25
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default How to Compare two QString in the form of QDateTime ?

    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 ?

  2. #2
    Join Date
    Feb 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows

    Default Re: How to Compare two QString in the form of QDateTime ?

    Quote Originally Posted by George Neil View Post
    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.

    Qt Code:
    1. QDateTime::fromString("10/10/2008 10:15 Am", "dd/MM/yyyy hh:mm ap")
    To copy to clipboard, switch view to plain text mode 

    and then compare them.

  3. #3
    Join Date
    Jun 2008
    Posts
    25
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default Re: How to Compare two QString in the form of QDateTime ?

    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 ?
    Last edited by George Neil; 1st March 2010 at 06:54.

  4. #4
    Join Date
    Feb 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Windows

    Default Re: How to Compare two QString in the form of QDateTime ?

    Quote Originally Posted by George Neil View Post
    Okay, then How to find the Date time format from a given QString.

    Whats the best / easy method ?
    You have a known string format?

  5. #5
    Join Date
    Jun 2008
    Posts
    25
    Thanks
    9
    Thanked 1 Time in 1 Post

    Default Re: How to Compare two QString in the form of QDateTime ?

    No, there are chances for different date/time formats in the string, like M/D/YYYY OR MM/DD/YYYY

Similar Threads

  1. Initialize QDateTime by a QString
    By mattia in forum Newbie
    Replies: 2
    Last Post: 14th March 2008, 13:42
  2. Replies: 4
    Last Post: 31st January 2008, 20:44
  3. Compare
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 14th March 2007, 15:03
  4. Compare QString alphabet position
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2006, 16:50
  5. Replies: 1
    Last Post: 30th June 2006, 05:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.