MySql time problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

MySql time problem

Post by itsmani1 »

Hi,

I am using a shared hosting which has EST US time, since i am on shared hosting that's why i cannot change the server time zone but i wanted to display local Pakistan time to my users. For example a user lists an item he/she wants to see at what time item was listed and they wanted to see it in Pakistan time not EST US time.

What's the best solution to do this? Wanted to do it on database level..

Thanks
-Mannan
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: MySql time problem

Post by pbs »

You can set time zone using date_default_timezone_set() function
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Re: MySql time problem

Post by itsmani1 »

date_default_timezone_set()

is a php function my time is stored in mysql sir
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: MySql time problem

Post by Weirdan »

You can set sql session timezone on a connection:
[sql] SET session time_zone="Asia/Karachi"; [/sql]
After that all TIMESTAMP values will be auto-converted to the specified timezone upon retrieval (date and datetime values will not be affected though).
Post Reply