Page 1 of 1

Date difference due to different Time Zones

Posted: Sun Jan 20, 2008 8:49 am
by nikhilvijayanv
I want to make a MLM website which need to work in Indian Timezone. and my hosting company's time is different from indian timezone..

is there any way i can make the date in php and mysql have the date and time of India. ??

Re: Date difference due to different Time Zones

Posted: Sun Jan 20, 2008 10:29 am
by JAM
Try date_default_timezone_set()

Example:

Code: Select all

<?php
    echo date('Y:m:d H:i:s')."<br />";
    date_default_timezone_set('Asia/Calcutta');
    echo date('Y:m:d H:i:s');
?>
Result:
2008:01:20 16:32:48
2008:01:20 22:02:48
Note that this only affects php's scripting, not the MySQL itself. It should however be easy enough to understand what to do from here. :wink:

Re: Date difference due to different Time Zones

Posted: Sun Jan 20, 2008 10:46 am
by nikhilvijayanv
Thanks for helping.. this function is only supported in php 5 ..

What would i have to do if i am using php 4.. just curious to know

Re: Date difference due to different Time Zones

Posted: Sun Jan 20, 2008 10:50 am
by Oren
Move to PHP5? :P

Re: Date difference due to different Time Zones

Posted: Sun Jan 20, 2008 11:03 am
by JAM
Oren wrote:Move to PHP5? :P
Yah, but...
a) not all have that power over their hosts...
b) making scripts that works for both 4 and 5 is a big plus... :wink:

Code: Select all

<?php
    echo date('Y:m:d H:i:s')."<br />";
 
    // PHP 5
    // date_default_timezone_set('Asia/Calcutta');
    // echo date('Y:m:d H:i:s');
 
    // PHP 4
    putenv("TZ=Asia/Calcutta");
    echo date('Y:m:d H:i:s');
 
?>

Re: Date difference due to different Time Zones

Posted: Sun Jan 20, 2008 12:07 pm
by Oren
JAM wrote:not all have that power over their hosts...
Why not? "I want PHP5 or I move to another host". If they can't give you what you need, move on to another one who can.
JAM wrote:making scripts that works for both 4 and 5 is a big plus...
It is? Sorry I didn't know, I thought it was exactly the opposite... ask our very kind ( :P ) Chris Corbyn and see what he thinks about it.

Re: Date difference due to different Time Zones

Posted: Sun Jan 20, 2008 2:06 pm
by JAM
Oren wrote:
JAM wrote:not all have that power over their hosts...
Why not? "I want PHP5 or I move to another host". If they can't give you what you need, move on to another one who can.
JAM wrote:making scripts that works for both 4 and 5 is a big plus...
It is? Sorry I didn't know, I thought it was exactly the opposite... ask our very kind ( :P ) Chris Corbyn and see what he thinks about it.
Sorry if I misunderstood.

I thought the question was about to solve the issue using the existing 'tools'. Yes, striking a deal like suggested with the host might be in order and solve the issue, but that wasn't really the question? And the asking Chris anything... I just don't understand your point. :drunk:
It's really off-topic anyways, so...


@ nikhilvijayanv :
Did it work as wanted?

Re: Date difference due to different Time Zones

Posted: Sun Jan 20, 2008 5:13 pm
by vigge89
Continuing on the off-topic for a teeny weeny while longer (sorry): Should I say welcome back JAM? :]
Knew I recognised your name from before when I was a PHP toddler :)