I want to save my countries local time(new zealand) in my database. I am using php but i dont know how to do it.
Please guide me out.
I want to save my countries local time(new zealand) in my database. I am using php but i dont know how to do it.
Please guide me out.
Use now() or sysdate() in your insert query:
insert into mytable set datetimefield=sysdate()
Just make sure that the server time is synchronised, and that it's in the right timezone. Otherwise you'll have to do some extra tricks to shift the date/time.
If timing is crucial, keep this in mind:
As of MySQL 5.0.13, SYSDATE() returns the time at which it executes. This differs from the behavior for NOW(), which returns a constant time that indicates the time at which the statement began to execute. (Within a stored routine or trigger, NOW() returns the time at which the routine or triggering statement began to execute.)
Hi there.
This
date('O');
will give you the difference to Greenwich time (GMT) in hours for the server Example: +0200
You will need to know your own timezone's GMT offset.
Use those two numbers to work out how far the server is ahead of you or behind you and then use strtotime() to get your current time.
For instance if the server is 2 hours ahead of you you would use
date("Y-m-d H:i:s", strtotime("-2 hours"));
HTH
JG
If you're using timestamp field and MySQL database, you can just call CURRENT_TIMESTAMP. I recommend not saving time data as unix timestamp since you can use date specific functions on date/timestamp fields as well as extract unix timestamp from them.