Atozed Forums
DateTime format - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: DateTime format (/thread-2112.html)

Pages: 1 2


DateTime format - Mikael Nilsson - 11-11-2020

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


RE: DateTime format - kudzu - 11-11-2020

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/51317959/how-to-convert-string-to-date-in-delphi


RE: DateTime format - Mikael Nilsson - 11-12-2020

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)


RE: DateTime format - kudzu - 11-12-2020

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.


RE: DateTime format - Mikael Nilsson - 11-12-2020

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)


RE: DateTime format - kudzu - 11-13-2020

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.public.delphi.internet.winsock/c/XbnvGoNkeh0?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.


RE: DateTime format - Jose Nilton Pace - 11-13-2020

Hi Mikael, try change:
  SysUtils.FormatSettings.ShortDateFormat := 'yyyy-mm-dd';
to:
  WebApplication.RegionalSettings.ShortDateFormat := 'yyyy-mm-dd';


RE: DateTime format - kudzu - 11-13-2020

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


RE: DateTime format - Mikael Nilsson - 11-16-2020

(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?


RE: DateTime format - Jose Nilton Pace - 11-16-2020

Sorry, IWInit;