1

I have created a table where the payment time is payment_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP into my database. When I insert a value while keeping the payment_time field blank, the time has stored on GMT -7 where I am staying in GMT +00. I think it is because the server time zone is GMT -7. How can I insert my local time into database? Even if it is not possible then I want at least to get the local time when on output from database(I mean while query).

fedorqui
  • 275,237
  • 103
  • 548
  • 598
user1946440
  • 349
  • 1
  • 5
  • 13
  • possible duplicate of [MySQL timezone change?](http://stackoverflow.com/questions/3451847/mysql-timezone-change) – Barmar Feb 07 '13 at 10:06

2 Answers2

1

Check out this. http://dev.mysql.com/doc/refman/5.5/en//time-zone-support.html

To change global time zone:

mysql> SET GLOBAL time_zone = timezone;
j0k
  • 22,600
  • 28
  • 79
  • 90
Towny1991
  • 11
  • 4
0

Put the time zone setting command in that script from where you are inserting the time SET time_zone = 'country_name/city'; you can go through the links of different country and states in php website. Suppose i am executing xyz.php script which will insert time into database, then it should look like this

<?php date_default_timezone_set('Asia/Kolkata'); //you ned to put this line of code at the start of the script ?>
Raul
  • 579
  • 1
  • 5
  • 17
  • Could you please explain where exactly I have to put the `SET time_zone = 'Europe/London';` in my script? Here are the files: `https://www.dropbox.com/sh/lfef67brewx7rub/wYRP72bDh7` the member.class is the file where I am inserting value. – user1946440 Feb 07 '13 at 10:20
  • Check my answer i which i have edited. hope you will get idea. – Raul Feb 07 '13 at 10:33
  • I am afraid.. it is the same as before... :-( – user1946440 Feb 07 '13 at 10:48
  • Basically what i think is that, you are executing a php script and you want time according to your region. if it is the case then put the above mentioned php code at the start of your script. – Raul Feb 07 '13 at 10:52
  • Thats what I did but it is storing with the server time zone @Rahul Jha – user1946440 Feb 07 '13 at 10:55
  • you have two options according to me. either remove default current time stamp and make it null. now whatever you will insert through php script it will take that time. else check your php.ini setting date.timezone or check out this link http://dev.mysql.com/doc/refman/5.5/en//time-zone-support.html – Raul Feb 07 '13 at 11:16
  • I have set the timestamp to null. After that, I put ``. Do I have to put any thing in mysql query? If yes then what should I put? @Rahul Jha – user1946440 Feb 07 '13 at 11:40
  • no you don't need to put anything. change the time according to your country and state. otherwise it will show indian time. – Raul Feb 07 '13 at 11:43
  • I did but no value is inserted because on my query I left blank for the time field. – user1946440 Feb 07 '13 at 12:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/24118/discussion-between-rahul-jha-and-user1946440) – Raul Feb 07 '13 at 12:14