PHP & MySQL time zone

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nadinchathura
Forum Newbie
Posts: 2
Joined: Thu Jun 12, 2008 10:28 pm

PHP & MySQL time zone

Post by nadinchathura »

Hey guys,

My servers are allocated in USA. Normally when i save time using MySQL NOW() function, time saved on DB in USA time. At the time of retrieving time from PHP i get USA time. how can i change it to Sri Lankan time zone which is equals to Sri Lanka current time?

Please give me some code to do this.

Thak guys

Chathu
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: PHP & MySQL time zone

Post by WebbieDave »

The strtotime and date functions plus a little arithmetic is all you need.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: PHP & MySQL time zone

Post by Kieran Huggins »

you can set the MySQL server timezone:
http://dev.mysql.com/doc/refman/5.0/en/ ... pport.html
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP & MySQL time zone

Post by RobertGonzalez »

And you can set the PHP timezone in php.ini

And no one here is ever going to just give you code. Code it yourself and ask for help when you run into snags.
nadinchathura
Forum Newbie
Posts: 2
Joined: Thu Jun 12, 2008 10:28 pm

Re: PHP & MySQL time zone

Post by nadinchathura »

thanks guys... :D thank you so much
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP & MySQL time zone

Post by Eran »

Check out date_default_timezone_set for on the fly timezone setting - http://www.php.net/date_default_timezone_set
Post Reply