How do you force cxDateEdit to reset time to 00:00:00 ? Actually I do not need time and have changed its property to date only but somehow the time still gets included in the result. Not visible, but enough to make my query result wrong. I must reset time to 00.
Asked
Active
Viewed 590 times
-1
-
2Just take `Trunc(cxDateEdit1.DateTime)`. This behaviour is expected. – Warren P Apr 14 '13 at 22:31
2 Answers
3
DateUtils.DateOf
returns just the date portion of a date time variable.
// QueryDate is a TDateTime variable
QueryDate := DateUtils.DateOf(cxDateEdit1.DateTime);
YourQuery.ParamByName('TheDate').AsDateTime := QueryDate;
For future readers using older versions of Delphi that don't have the DateUtils
unit, you can accomplish the same thing using Trunc
. (If you have DateUtils
, it's much clearer what you're doing if you use DateOf
instead.)
QueryDate := Trunc(cxDateEdit1.DateTime);

David Heffernan
- 601,492
- 42
- 1,072
- 1,490

Ken White
- 123,280
- 14
- 225
- 444
-
-
@Warren, the last time I posted `Trunc` here instead of recommending `RecodeTime` I got negative comments and a couple of downvotes. I covered both bases here. :-) I personally use `Trunc` because it's less typing and I know what it does. – Ken White Apr 14 '13 at 22:41
-
I prefer `Trunc()` because it is obvious what it does. Truncates a floating point number. That in turn documents the fact that the reader needs to know. DayOf is a mystery. – Warren P Apr 14 '13 at 22:56
-
@Warren No I meant DateOf. Silly typo. And yes, Trunc does truncate a floating point number. But how that relates to dates is a mystery. Using Trunc to work with dates is a horrid implementation detail leak. – David Heffernan Apr 14 '13 at 23:23
-
I guess I figure that TDateTime will always be a floating point number and ignoring that fact leads to all manner of assumptions, which is horrid. – Warren P Apr 16 '13 at 14:01
0
There's a SaveTime property in Properties which you can set to False. This will store only the date.

Jason
- 2,572
- 3
- 34
- 41