0

I have my project based in India and my hosting server located somewhere that is at a difference of -5:30 HRs from Indian time.

So my time being stored in database is coming as based on there timings. How can I rectify this in PHP so that the time actually gets stored on India.

I tried using date_default_timezone_set('Asia/Kolkata');

but still the time gets stored with a difference of -30mins to -45mins. What could be possible code fort his so that the time sets exactly according to Indian timings. Any advice will be very helpful.

Raghav
  • 388
  • 1
  • 12
Anand
  • 33
  • 1
  • 9
  • You have to determine the source of your date. For example, the date may be set from the application side, i.e the PHP or from the database side, i.e MySQL. However, does your hosting offers custom php.ini? – SaidbakR Dec 07 '17 at 06:26
  • @SaidbakR Thanks for time. Yes the date is being processed through application side, date(d-m-Y) – Anand Dec 07 '17 at 06:47
  • Do you know what timezone your server is ? – Himanshu Upadhyay Dec 07 '17 at 12:58

4 Answers4

0
  • Step-1: Set timezone as asia/kolkata
  • Step-2: Now, first store the date in local variable, example: $mydate = date('Y-m-d H:i:s'); and just print the variable value to see, if it is the time as you want?
  • Step-3: If yes then store $mydate variable value in database.
Hetal Chauhan
  • 787
  • 10
  • 22
  • Thanks for your time. Yes I have done this and in that case I am getting a difference of -30mins to -45 mins – Anand Dec 07 '17 at 06:48
0

You can set the timezone in the database.

Few more threads of the same topic are here:

ino
  • 2,345
  • 1
  • 15
  • 27
0

If you want to store the current date/time on your database and use the timezone you have. Try to use now() function.

Reference Link: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_now

not_null
  • 111
  • 10
0

As you said your server is running at -5.30 hours from India, get the dates like this:

date('d-m-Y H:i:s',strtotime('+330 minutes'));  // this adds 5.30 hours to the current time. 
Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33
  • Thanks @HimanshuUpadhyay for your time. But I want to save any user's time across the globe to their local time irrespective of server time. As u suggested, it holds good only for India timezone – Anand Dec 13 '17 at 06:25