I am using Laravel 6. I have created a ticketing system and successfully uploaded on server.
I am storing ticket creation time in created_at field in my MySQL database. The problem is sometimes the timestamp in created_at field is correct and sometimes it stores wrong timestamp.
The problem is weird and I cannot figure it out and don't know how to debug this issue.
My timezone in Laravel config/app.php is set to Asia/Kolkata
'timezone' => 'Asia/Kolkata',
Here is my ticket create method
$ticket_tracker = TICKET_TRACKER::create
([
'ticket_no' => $ticket_number,
'partner_id' => $partner_id,
'team_id' => $team_id,
'priority_id' => $priority_id,
'opened_date' => $opened_date,
'created_by' => $user_id,
]);
created_at field is not included in above code as Laravel stores time itself.
Table Structure
After further digging into issue I have discovered that MySQL stored correct timestamp when I created a ticket for testing. After few hours I have created the another ticket which is saved with correct timestamp but timestamp of my old ticket changed itself (I don't know how this happened).
Also I found that my global and session time zone is system which is UTC I think because my current time is 5.30 hour ahead of timestamp displayed by this command CURRENT_TIMESTAMP
Because you not provide created_at & updated_at values by you query the values is generated on MySQL side according MySQL server time and timezone.
For check get MySQL current time use next simple query:
SELECT @@global.time_zone, @@session.time_zone, CURRENT_TIMESTAMP;
If CURRENT_TIMESTAMP is not match to your time zone you can change timezone settings following documentation