[Qt-interest] [Solved] Strange problem storing and retrieving and comparing QTime/QDataTime
Mihail Naydenov
mlists at ymail.com
Tue Nov 17 18:29:17 CET 2009
----- Original Message ----
> From: Mihail Naydenov <mlists at ymail.com>
> To: qt-interest at trolltech.com
> Sent: Tue, November 17, 2009 7:07:44 PM
> Subject: Re: [Qt-interest][Solved] Strange problem storing and retrieving and comparing QTime/QDataTime
>
> Yes, thank you, Thiago , binding a QDateTime to a table field value saves it as
> Qt::ISODate, which has signature YYYY-MM-DDTHH:MM:SS
> this obviously discards the milliseconds.
> When read back the milliseconds are reset to zero.
>
> So, if one first converts the datetime toString("dd.MM.yyyy hh:mm:ss.zzz")
> before binding
> than later reads it back as string first (not toDateTime() on the table data
> QVariant) and builds the datetime manually, using the string and the same
> signature ("dd.MM.yyyy hh:mm:ss.zzz") everything is ok :) (assuming sqlite)
>
> I guess its easier to just convert toTime_t instead.
Just to add that the best signature to use is yyyy-MM-ddThh:mm:ss.zzz
which actually is ISO compatible and natively understood by sqlite.
The best part is, it only needs to be manually specified upon saving, later its ok to just call .toDateTime() on the table data!
To Qt team:
I guess it could be good idea to store in that format by default, when binding a QDateTime object to a db. Then everything will work out of the box.
>
> Thanks again
> MihailNaydenov
>
>
> ----- Original Message ----
> > From: Frank Hemer
> > To: qt-interest at trolltech.com
> > Sent: Tue, November 17, 2009 5:04:24 PM
> > Subject: Re: [Qt-interest] Strange problem storing and retrieving and
> comparing QTime/QDataTime
> >
> > On Tuesday 17 November 2009 15:40:49 Thiago Macieira wrote:
> > > Now, remember that QDateTime keeps the time precision in *milliseconds*,
> > > whereas time_t has a resolution of seconds. My guess is your roundtrip
> > > through the database discarded the millisecond component (your source was
> > > file.lastModified(), which does have millisecond resolution).
> >
> > Also note that some databases (depending on the date type used) don't have a
> > millisecond precision (mssql has ~3msec precision by default).
> >
> > Frank
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list