Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Couple of questions regarding dates
Sun, May 6 2018 11:31 PMPermanent Link

Paul Coshott

Avatar

Hi All,

In my main forms on create event, I have the following:

 //date format options
 FormatSettings.ShortDateFormat := 'd/MM/yyyy';

1. What do I need to do (if anything) to tell the app to use the local date settings? So if in the US M/D/Y or if in Australia D/M/Y.

2. If I manually type in the date 7/5/18, I get displayed: 7/05/1918
How do I make sure manually entered 2 digit years become 20XX ?

Thanks,
Paul
Mon, May 7 2018 7:12 AMPermanent Link

Uli Becker

Just assign new values to the FormatSettings properties in the initialization section of your main form.

Uli
Mon, May 7 2018 9:45 AMPermanent Link

Ralf Mimoun

1. If you want to set the format without user interaction, you would need some kind of geolocation and a list of formats per country. Not the easiest task.

2. Take a look at (T)FormatSettings.TwoDigitYearCenturyWindow.
Thu, May 10 2018 5:52 PMPermanent Link

Paul Coshott

Avatar

Hi Guys,

>> 2. Take a look at (T)FormatSettings.TwoDigitYearCenturyWindow.

Thanks for the answers. I have read and re-read the help file description on the TwoDigitYearCenturyWindow property, and really don't understand exactly how this works.

What I would like to end up with is:

years entered as 00 up to current year (18) + 5 (so 23) are interpreted as 20XX
years entered as 24 up to 99 are interpreted as 19XX

What value do I need in the TwoDigitYearCenturyWindow property to do this?

Thanks,
Paul
Fri, May 11 2018 5:10 AMPermanent Link

Ralf Mimoun

Strange... I tried this code:

 for i := -100 to 100 do begin
   FormatSettings.TwoDigitYearCenturyWindow := i;
   s1 := DateToStr(StrToDate('02.03.23'));
   s2 := DateToStr(StrToDate('02.04.24'));
   logoutput(inttostr(i) + ' ' + s1 + ' ' + s2);
 end

And all I get is "02.03.1923 02.04.1924". It seems that Tim should take a look.
Fri, May 18 2018 2:10 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Ralf,

<< Strange... I tried this code: >>

The issue is that the TwoDigitYearCenturyWindow logic only kicks in when the year format for the date format is 'yy', not when it's 'yyyy'.  I've modified this for B13 so that it kicks in when the *specified* year is a partial year.

Tim Young
Elevate Software
www.elevatesoft.com
Image