DateTime format

<< Click to Display Table of Contents >>

Navigation:  Forum >

DateTime format

Forum link

 

Pages: 1 2

 


 

11-11-2020, 01:53 PM:

 

I have problem with DateTime format.

 

Delphi version is 10.3.3 and IW 15.2.3

 

In Delphi/Intraweb I do this command that's fails with this error: '2020-11-11 14:22:57.660' is not a valid date and time

 

wDateTime := strToDateTime(ContinueTime);

 

wDateTime is a TDateTime

 

ContinueTime is a string containing the value '2020-11-11 14:22:57.660'

 

I have also done these settings in ServerController

 

procedure TIWServerController.IWServerControllerBaseConfig(Sender: TObject);

 

begin

 

  SysUtils.FormatSettings.ShortDateFormat := 'yyyy-mm-dd';

 

  SysUtils.FormatSettings.ShortTimeFormat := 'hh:nns';

 

  SysUtils.FormatSettings.LongTimeFormat := 'hh:nns.zzz';

 

end;

 

 

 

I forgot to mention that this code works in SA buy not as a ISAPI.dll

 


 

11-11-2020, 06:15 PM:

 

ISAPI by default runs as a different user which may have different region settings. In general its a bad idea to modify the global ones. I suggest instead you specify the format you want when converting:

 

https://stackoverflow.com/questions/5131...-in-delphi

 


 

11-12-2020, 09:51 AM:

 

Ok, but that instruction has worked for over 8 years.

 

It must be something that have changed in Delphi 10.3.3 or IW.

 

And it is very unfortunate that code working in SA does not

 

work in a ISAPI.ddl. This makes it impossible for us developers

 

to track down errors.

 

Does the code in IWServerControllerBaseConfig work?.

 

I want the datetime string to be what I specify (Not a user specific)

 


 

11-12-2020, 03:48 PM:

 

Its not IW because the code you are using is pure RTL, not IW code. strToDateTime is RTL.

 

As I explained, SA and ISAPI by default will run as different users on your system and the region settings of each user can alter the behavior of strToDateTime. This is why its always best to code the format directly and never rely on region settings for server based applications.

 

Likely a SP or some other change altered the region settings of the user your ISAPI runs under.

 


 

11-12-2020, 03:58 PM:

 

SP?

 

I have done:

 

ContinueTime:String;

 

wDateTime: TDateTime;

 

fs: TFormatSettings;

 

begin

 

fs := TFormatSettings.Create;

 

fs.DateSeparator := '-';

 

fs.ShortDateFormat := 'yyyy-mm-dd';

 

fs.TimeSeparator := ':';

 

fs.ThousandSeparator := '.';

 

fs.ShortTimeFormat := 'hh:mms.zzz';

 

fs.LongTimeFormat := 'hh:mms.zzz';

 

ContinueTime:='2020-11-12 15:35:18.760';

 

wDateTime := strToDateTime(ContinueTime,fs);

 

and it still abends when I test it in ISAPI and not in SA.

 

(Skip other users. It's me that are testing the ISAPI.dll)

 


 

11-13-2020, 05:46 PM:

 

This is really odd..... this is not an IW issue though as this is an RTL call (part of Delphi libraries). Odd though, I found non IW user with the SAME issue dating back to 2001!

 

https://groups.google.com/g/borland.publ...keh0?pli=1

 

I'll ask some others to take a look at this thread, but as this is a Delphi API call and a Delphi issue I suggest you also post on a Delphi support forum.

 


 

11-13-2020, 06:10 PM:

 

Hi Mikael, try change:

 

  SysUtils.FormatSettings.ShortDateFormat := 'yyyy-mm-dd';

 

to:

 

  WebApplication.RegionalSettings.ShortDateFormat := 'yyyy-mm-dd';

 


 

11-13-2020, 06:49 PM:

 

Thanks JNP. Odd that even when he passes an explicit format string it still fails though.

 


 

11-16-2020, 03:34 PM:

 

(11-13-2020, 06:10 PM)Jose Nilton Pace Wrote: [ -> ]Hi Mikael, try change:

 

  SysUtils.FormatSettings.ShortDateFormat := 'yyyy-mm-dd';

 

to:

 

  WebApplication.RegionalSettings.ShortDateFormat := 'yyyy-mm-dd';

 

I get Undeclared identifier....

 

Do I have to add a specific unit?

 


 

11-16-2020, 06:32 PM:

 

Sorry, IWInit;