PDA

View Full Version : Double to date conversion



ShamusVW
27th August 2010, 09:45
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.


ui->labelDate->setText("Date : " + list.at(1));

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.

ShamusVW
27th August 2010, 12:28
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.

norobro
28th August 2010, 00:41
You can let MySQL handle the conversion:
select date('1899-12-31 00:00:00'+ INTERVAL your_date_column * 24*3600 SECOND) from your_db;
mysql> select date('1899-12-31 00:00:00'+ INTERVAL 40416.25 * 24*3600 SECOND) as date;
+----------------+
| date |
+----------------+
| 2010-08-27 |
+----------------+

ShamusVW
28th August 2010, 04:44
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.

Urthas
28th August 2010, 05:03
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.

norobro
28th August 2010, 14:18
Or if your QStringList contains a double, why won't something like this work as a query?
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;