Results 1 to 6 of 6

Thread: Double to date conversion

  1. #1
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Double to date conversion

    I am reading a value from a mySQL database that is a double, representing a date value.
    I am wanting to pass this value to a QLabel.

    Qt Code:
    1. ui->labelDate->setText("Date : " + list.at(1));
    To copy to clipboard, switch view to plain text mode 

    However, it uses the ISODate and my output is [say] 2010-08-18T00. I do not want the "T00" at the end, and it is picking it up because of a decimal point existing in my data. I only want it to use the date part. I don't want to first convert the data to an integer first if possible.

    How do I specify to use [say] "yyyy/mm/dd" as my format? I see there is another ENUM QT::TextDate, but I'm not sure how to specify enums.

    Thanks.

  2. #2
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Double to date conversion

    Apologies, the date format is saved "2010-08-18 00:00:00" and hence it converts to "2010-08-18T00".
    However, I am still looking for a way to convert say 40416.25 (double) to 2010-08-27, i.e. to drop the 0.25 = 6am.

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Double to date conversion

    You can let MySQL handle the conversion:
    Qt Code:
    1. select date('1899-12-31 00:00:00'+ INTERVAL your_date_column * 24*3600 SECOND) from your_db;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. mysql> select date('1899-12-31 00:00:00'+ INTERVAL 40416.25 * 24*3600 SECOND) as date;
    2. +----------------+
    3. | date |
    4. +----------------+
    5. | 2010-08-27 |
    6. +----------------+
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Double to date conversion

    Unfortunately I'm not retirieving just this one column, I am retrieving all at once by a SELECT * FROM... statement, so I already have the data sitting in a QStringList.

  5. #5
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Double to date conversion

    Quote Originally Posted by ShamusVW View Post
    Unfortunately I'm not retirieving just this one column, I am retrieving all at once by a SELECT * FROM... statement, so I already have the data sitting in a QStringList.
    Well, if it's a list of fixed-width QStrings (which is what it sounds like) you could use QString::left(10) on each entry in the list.

  6. #6
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Double to date conversion

    Or if your QStringList contains a double, why won't something like this work as a query?
    Qt Code:
    1. select col_0, col_1, col_2, date('1899-12-31 00:00:00'+ INTERVAL your_date_column * 24*3600 SECOND), . . . col_n from your_db;
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 7
    Last Post: 28th December 2010, 20:27
  2. Hex Conversion
    By umulingu in forum Newbie
    Replies: 5
    Last Post: 5th March 2010, 18:07
  3. Replies: 3
    Last Post: 27th December 2009, 00:00
  4. Replies: 2
    Last Post: 24th June 2009, 15:38
  5. How to default Date-Edit Widget to system date
    By JohnToddSr in forum Qt Tools
    Replies: 4
    Last Post: 17th January 2007, 19:18

Tags for this Thread

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.