Let's imagine this situation: A user selects a date (e.g. 2025-01-01) from a date input in UTC+4. Because the time is not important in this case, by default the time will be set to midnight (00:00 UTC+4).
From my understanding, the best practice here is the front-end should send the date as an ISO string in UTC (CMIIW). And, by default, JSON.stringify would convert the date object (2025-01-01 at 00:00 UTC+4) to an ISO string in UTC (2024-12-31T20:00:00.000Z).
Because I only want to know the date, I gave the field a data type of date.
Schema::create('foobar', function(Blueprint $table) {
$table->date('date');
}
In the back-end, the ISO string would get converted to an instance of Carbon. And when the date is inserted to the database, the time is not stored, leaving only the date (2024-12-31 in UTC).
Now the problem is, when i want to get the date back, I would like to convert it back to UTC+4. But since the time is not stored in the database, when the date is converted back to Carbon instance the time would just be set to midnight (2024-12-31 at 00:00 UTC). So in the front-end when i convert it to UTC+4 the date would be (2024-12-31 at 04:00 UTC+4), which is not what I want (supposed to be 2025-01-01).
I know a couple of workarounds to solve this, but I'd like to know which one's best. Should I not send the date as an ISO string? Should I use datetime instead? or something else entirely?
For context, I'm using React, Inertia, and MariaDB as my database.