Atozed Forums

Full Version: DateTime format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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:nnConfuseds';
  SysUtils.FormatSettings.LongTimeFormat := 'hh:nnConfuseds.zzz';
end;

I forgot to mention that this code works in SA buy not as a ISAPI.dll
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
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)
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.
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:mmConfuseds.zzz';
fs.LongTimeFormat := 'hh:mmConfuseds.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)
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.
Hi Mikael, try change:
  SysUtils.FormatSettings.ShortDateFormat := 'yyyy-mm-dd';
to:
  WebApplication.RegionalSettings.ShortDateFormat := 'yyyy-mm-dd';
Thanks JNP. Odd that even when he passes an explicit format string it still fails though.
(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?
Sorry, IWInit;
Pages: 1 2