I have a form on the front end which has a date range picker. A user selects their date and time with no issues. The data is inserted into the database with no issues.
The issue is that the time being selected on the front end is being treated as UTC time versus the local users time.
So, when a user selects 10 AM, the time being inserted is 10 AM, but when it is retrieved, it is converted to the local user time. For the Central Time zone, it is currently -5 UTC, so it shows 5 AM.
I have not been able to see any setting in the Date Range Picker that would give the option for the time to be considered local user time, so that means I need to look at a server action solution. (I think).
The issue is I am not sure how to convert the time on the server side. I attempted to use "toUTCTime()" formatter on the Database Updater but it throws an ER_TRUNCATED_WRONG_VALUE error, I presume because the database field is datetime and it is trying to insert "2024-07-01T10:00:00.000Z" versus "2024-07-01 10:00:00".
I suppose you compare the date entered on the page with the date saved on db?
Have you tried showing the saved date on your page with a formatDate to see this date?
Anyway, how you want to save the dates? serverTime, UTC, local?
No matter how you save it in your db, you can always translate/show the local time on the front-side (as long as you know how it is saved in your db)
The Server Connect Settings is set to Etc/UTC. The format that the datetime is saved in the database is UTC because users may be from any of the U.S. time zones and we need a consistent way of handling dates/times.
When the user selects a date/time using the Date Range Picker, they are using the date/time of what time they are located at.
What is inserted into the database is the exact date and time that they selected.
When the server connect retrieves the data, it shows it under network as the time they selected.
When displaying the date/time on the page, it shows the local time.
There is no date/time conversion coded on the front end (only formatting) so I assume it is being done automatically.
So what I need to know how to do is using the Date Range Picker, insert the date/time selected into the database in UTC time since it is being converted to local time on the front end.
The issue really is not about the retrieval of the data, but the insertion of the data.
I have no issue with the data automatically being converted to local time.
However, trying to explain to users to submit the data in UTC time is difficult and causing complaints and issues. We tried it this way, but users do not like to have to think and do math.
The way I am looking at it, if it automatically converts UTC to local time on retrieval, there must be a way to convert local to UTC on insertion. I wonder if @patrick has any thoughts on this.