Date difference due to different Time Zones

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
nikhilvijayanv
Forum Newbie
Posts: 2
Joined: Sun Jan 20, 2008 8:44 am

Date difference due to different Time Zones

Post 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. ??
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Date difference due to different Time Zones

Post 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:
nikhilvijayanv
Forum Newbie
Posts: 2
Joined: Sun Jan 20, 2008 8:44 am

Re: Date difference due to different Time Zones

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Date difference due to different Time Zones

Post by Oren »

Move to PHP5? :P
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Date difference due to different Time Zones

Post 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');
 
?>
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Date difference due to different Time Zones

Post 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.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Date difference due to different Time Zones

Post 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?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Re: Date difference due to different Time Zones

Post 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 :)
Post Reply