Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Date / Now
Wed, Jan 30 2019 11:34 AMPermanent Link

Eivind

All

Just saw something odd today and maybe its designed this way. I'm setting a DateTimePicker.SelectedDate to todays date before showing the user the form. If I use DateTimePicker.SelectedDate := Date I get 29/01/2019 and if I use DateTimePicker.SelectedDate := Now I get 30/01/2019.

When I test this its 30 minutes before midnight on the 30/01/2019 so I would expect  the 30'th of Jan. However, before I have been using DateTimePicker.SelectedDate := Date and just now I saw the problem with the date. Its actually almost 31 Jan and still "Date" show 29'th Jan.

Obviously I will continue to use "Now" to generate the date. Just wondered if this was as designed?

Cheers
Eivind
Thu, Jan 31 2019 5:17 AMPermanent Link

Walter Matte

Tactical Business Corporation

Eivind:

Timestamps are still Localized so - yes this is as designed.

Here is how I work with Now.....

function NowFix : DateTime;
begin
 result := Now - (TimeZoneOffSet(now) * 60 * 1000);
end;

Walter
Thu, Jan 31 2019 9:48 AMPermanent Link

Eivind

Walter Matte wrote:

<<<<<Timestamps are still Localized so - yes this is as designed.>>>>>>

@Walter.

Understood... According the the manual on Now is says:
The Now function returns the current date and time. The return value is a DateTime value.
So that is as expected.

However, the Date function should only return a date and according  to the manual is says:
The Date function returns the current date. The return value is a DateTime value.

So if I used the Date and not Now, should't that give me the correct Date independent of the timezone? However, the return is a DateTime value according to the manual. Does that means the time part would be 00:00:00 and localised because of that?

Thanks for the modified Now function you mention! I will do some testing with that one to purely get the current date of the users computer independent of any timezones.
Fri, Feb 1 2019 2:58 AMPermanent Link

ooptimum

<< So if I used the Date and not Now, should't that give me the correct Date independent of the timezone? However, the return is a DateTime value according to the manual. Does that means the time part would be 00:00:00 and localised because of that? >>

According to sources:

function date()
{
  var $0 = new Date();
  return new Date($0.getFullYear(), $0.getMonth(), $0.getDate(), 0, 0, 0, 0).getTime();
};

you will receive a date in UTC (GMT) with zero time.
Fri, Feb 1 2019 2:34 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eivind,

<< Just saw something odd today and maybe its designed this way. I'm setting a DateTimePicker.SelectedDate to todays date before showing the user the form. If I use DateTimePicker.SelectedDate := Date I get 29/01/2019 and if I use DateTimePicker.SelectedDate := Now I get 30/01/2019. >>

Make sure to turn off this property:

https://www.elevatesoft.com/manual?action=viewprop&id=ewb2&comp=TCalendar&prop=LocalizeText

or

https://www.elevatesoft.com/manual?action=viewprop&id=ewb2&comp=TDateEditComboBox&prop=LocalizeText

depending upon which control you're using.

I need to remove that property in a new build because it doesn't apply to dates anymore now that EWB isn't localizing dates.

Tim Young
Elevate Software
www.elevatesoft.com
Image