Atozed Forums

Full Version: TIWBSInput and Date type input
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a TIWBSInput component to input a date and to load it from a database table field, type date.
This TIWBSInput is of type bsitDate, e.g., TIWBSinput.InputType := bsitDate.

When inputing I have no problem because I have the placeHolder on the field before input that shows me how to do it.
Where I do something like this:

MyComponentDate.Text := DateToStr(MyQuery.FieldByName('birthdayDate').AsDate);
or
MyComponentDate.Text := MyQuery.FieldByName('birthdayDate').AsString;

I get an error saying that it's an invalid date.

If my application is running as an application, that's ok but when I run it as a Windows Service, I'll get the error.
I know why this happens and that is because the regionals from the SYSTEM account, where the service is running, are different from the ones of the user account that is browsing the application on the browser.

How can I workaround this? How can I get the input pattern presented on the field?
Services run as a different user on Windows which may have different regional settings. I suggest you explicitly specify the date formats when calling date parsing routines to avoid this issue.
(12-16-2020, 03:17 PM)kudzu Wrote: [ -> ]Services run as a different user on Windows which may have different regional settings. I suggest you explicitly specify the date formats when calling date parsing routines to avoid this issue.

Yes, I know. I'd try everything.
Running service as a date format of dd/mm/yyyy and from the client side the date format is yyyy-mm-dd. So the IWBSInput has type bsitDate and the placeholder is yyyy-mm-dd.
When I try to load a date variable to this field, I get the error, because I can't get the date format from client side to be able to call date parsing routines with success.

How can I do it?
Thanks
Most web apps define the client date format in the application itself. Where I am, we use US date formats but when we log into our bank, they use EU formats. We have to use EU formats when we interact with our bank.

Some apps allow the user to define on a user by user basis.

The other option is to convert all dates before sending them to the server, or detecting what date format the user's browser is using (most complex and more likely to break).
(12-16-2020, 04:45 PM)kudzu Wrote: [ -> ]Most web apps define the client date format in the application itself. Where I am, we use US date formats but when we log into our bank, they use EU formats. We have to use EU formats when we interact with our bank.

Some apps allow the user to define on a user by user basis.

The other option is to convert all dates before sending them to the server, or detecting what date format the user's browser is using (most complex and more likely to break).

Ok, I understand. But if so, how does TIWBSInput component detects the user's browser date format, so that the placeholder for the input is yyyy-mm-dd, the same one that's on the regional settings of that user?
To be clear are you asking how the controls in the browser use the user of the browsers date settings? They use JS which like Delphi will use the user settings of that browser unless overridden. But passing that "format" from the browser to the server requires some translation.

This is why I said its easier to translate the input using JS into a fixed format for the server to consume rather than trying to handle whatever format the browser uses on the server side.
(12-17-2020, 06:59 PM)kudzu Wrote: [ -> ]To be clear are you asking how the controls in the browser use the user of the browsers date settings? They use JS which like Delphi will use the user settings of that browser unless overridden. But passing that "format" from the browser to the server requires some translation.

This is why I said its easier to translate the input using JS into a fixed format for the server to consume rather than trying to handle whatever format the browser uses on the server side.

Ok, I found a solution and a simple one and maybe I can help someone that have been the same problem.
The TIWBSInput has a property AsDateTime. So, rather then doing IWBSInput.Text := DateToStr(Date) to load some date, I do:

IWBSInput.AsDateTime := Date;
and after this for initializing the input field to empty date, I do
IWBSInput.Text := '';

This way and for all the time that I need to load a date type into the input field, I will no longer have the invalid date error. That simple. No matther what are the date format of the server where the Intraweb application is running and the date format of the client, no error what so ever.

Thanks for youi help. It's Delphi, by the way.
Thanks for sharing your solution.