Re: setting Delphi's DateTimePicker to current date


[ DelphiLand FAQ ]

Posted by webmaster on April 05, 2004 at 14:16:53:

In Reply to: Addind the system clock value to a dateand time picker posted by Necrom on January 16, 2004 at 04:08:58:

: I was wondering how to maker my date and time picker on my form display the current system date.
-------

You set the DATE property of Delphi's TDateTimePicker to today's date by setting it to the number of days that have elapsed since December 30, 1899.

The current system date in this format is given by the function DATE. So this gives us the following code:

DateTimePicker1.Date := Date;

Likewise, for yesterday you would write:

DateTimePicker1.Date := Date - 1;

Some more examples:

DateTimePicker1.Date := Date + 1; // tomorrow
DateTimePicker1.Date := 0; // December 30, 1899
DateTimePicker1.Date := 2; // January 1, 1900

To set the DateTimePicker to a particular date, for example April 5 2004:

DateTimePicker1.Date := EncodeDate(2004, 4, 5);

-------------------------

Important note:
In the following expression, the two words "date" men something completely different:

DateTimePicker1.Date := Date;

The "date" on the left side is a PROPERTY of the DateTimePicker, a value that you can READ as well WRITE, so you can change it to another value.

The "date" on the right is a Delphi FUNCTION, a value that can only be READ. So, don't try this: Date := 500;



Related Articles and Replies:



[ DelphiLand: free Delphi source code, tips, tutorials ]