#1 2013-07-31 10:28:06

lele9
Member
Registered: 2011-10-28
Posts: 170

tDateTime unexpected behaviour

hi,
i use a tdatetime for a tsqlrecord's property.
when i save just a tdate value in the database table i find correctly just the date value but if i save a null tdate value in the database table i find the time saved with timestamp.
i.e.

|TDateTimeField
|----------------
|2013-07-31                   <---- saved passing a tDate value
|T12:23:08                     <---- saved passing a null tDate value

why??
thanks,
Emanuele

Offline

#2 2013-07-31 11:13:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: tDateTime unexpected behaviour

What is a TDateTimeField?

Are you using the VCL wrapper?

How do you set "null" to a mORMot field (there is no such "null").

I do not understand your problem.
Perhaps it is an issue in the TClientDataSet itself.

Online

#3 2013-07-31 14:18:58

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: tDateTime unexpected behaviour

sorry, i explain wrong...

for TDateTimeField i mean a property of a TSQLRecord declared as TDateTime.

when i pass a Date value i find exactly the date i set (and only the date!)
when i pass a null Date (30 dec 1899) i find in database only the time (correctly dont save the date, but why the time???)

i hope that now the problem its clear.
thanks

Offline

#4 2013-07-31 14:25:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: tDateTime unexpected behaviour

Which database engine?

Online

#5 2013-07-31 14:41:10

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: tDateTime unexpected behaviour

SQLite

Offline

#6 2013-07-31 14:46:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: tDateTime unexpected behaviour

In Sqlite3, what is the column content?
It should be either null either ''.

Online

#7 2013-07-31 14:56:10

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: tDateTime unexpected behaviour

No, i have for example 'T11:08:10'

Offline

#8 2013-07-31 15:05:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: tDateTime unexpected behaviour

So I suspect you did not put a TDateTime value as 0 but very small...

Online

#9 2013-07-31 15:20:43

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: tDateTime unexpected behaviour

i assign date form tdatetimepicket like this

myTSQLRecord.myDateTime := myTDateTimePicker.Date;

why in database i find the time?

Offline

#10 2013-07-31 15:22:36

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: tDateTime unexpected behaviour

open the Sqlite3 database file with SynDBExplorer for instance (or any Sqlite3 tool), then look at the myDateTime column.

Online

#11 2013-07-31 15:37:11

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: tDateTime unexpected behaviour

when i told that in database i find its because i'm looking with SQLite Database Browser too...

Offline

#12 2013-07-31 19:03:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: tDateTime unexpected behaviour

Try to force myTSQLRecord.myDateTime := 0; in your code.

If the date is correct in the database, the problem is the date/time picker returned value.

Online

#13 2013-07-31 20:48:54

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

Re: tDateTime unexpected behaviour

I had a similar problem and it seems TDateTimePicker.Date also includes a time part.

Try:  trunc(myTDateTimePicker.Date)

Offline

#14 2013-08-01 07:41:47

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: tDateTime unexpected behaviour

thanks ab and esmondb!
the problem its TDateTimePicker so i make some test.
put TDateTimePicker on form and set kind property to dtkDate and Time property to null.
run the program.
all seems ok until i disable and re-enable the TDateTimePicker. In this case Time value is set to current time!
i work around with esmondb solution ---> trunc(TDateTimePicker.Date)
thanks again,
Emanuele

Offline

#15 2013-08-02 06:33:14

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: tDateTime unexpected behaviour

More accurately to use DateOf function from DateUtils unit.

Call DateOf to convert a TDateTime value to a TDateTime value that includes only the date information (sets the time portion to 0, which means midnight).

Offline

#16 2013-08-02 07:40:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: tDateTime unexpected behaviour

DateOf() is just a wrapper around Trunc().
And I suspect it would never change, unless you change the date/time COM format.
smile

Online

Board footer

Powered by FluxBB