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.
Code:
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.
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.
Re: Double to date conversion
You can let MySQL handle the conversion:
Code:
select date('1899-12-31 00:00:00'+ INTERVAL your_date_column * 24*3600 SECOND) from your_db;
Code:
mysql> select date('1899-12-31 00:00:00'+ INTERVAL 40416.25 * 24*3600 SECOND) as date;
+----------------+
| date |
+----------------+
| 2010-08-27 |
+----------------+
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.
Re: Double to date conversion
Quote:
Originally Posted by
ShamusVW
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.
Re: Double to date conversion
Or if your QStringList contains a double, why won't something like this work as a query?
Code:
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;