Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

incorrect time returned in laravel

Tags:

php

datetime

This is a strange problem

I am using date functions to get time too but it returns wrong time

return date('Y-m-d H:i:s');

This returns 2017-4-21 09:41:44 but the current time is 14:41:44 There is something wrong with hours. I tried NOW() in MySQL and it gave me correct timing but laravel PHP did not. Can someone help?

like image 922
Alen Avatar asked Apr 21 '17 09:04

Alen


People also ask

How do I set timezone dynamically in laravel?

If you want to keep a new time zone for all future requests, you need to use a package like larapack/config-writer to be able to save the time zone to the app config file. Another way to handle this is to keep time zone in DB, fetch it in every request and set it with config(['app. timezone' => $timezone]) dynamically.

Why laravel project is not working on server?

Based on reading your question and your comments below I would check the following. Make sure that /storage folder exists and that it has proper folder permission you can use 777 for testing, but make sure to change it when you are done. To do this type sudo chmod 0777 -R /storage when inside root.


1 Answers

In laravel project go to project/config there is a file app.php, in this file search for:

'timezone' => '';

pass your timezone value in it like:

'timezone' => 'Asia/Kolkata', // I am using this for India

And try again, now you will get the correct time as per your timezone.

Note: After passing the timezone value run the command php artisan config:cache to clear the cache so that you get the updated data.

Timezone list reference

like image 105
Mayank Pandeyz Avatar answered Oct 19 '22 16:10

Mayank Pandeyz