Page 1 of 1
changing server time to my time
Posted: Wed Jul 17, 2002 3:49 am
by mike
Hi....... me server time is 5 hours behind me (i.e when i post news it says time is 5am instead of 10am) im sure I rerad of a way to change this but for the life of me I can not find it any more!
all help much appreciated....
mike
Posted: Wed Jul 17, 2002 4:15 am
by will
what are you using to calculate the date? if you enter it manually, you'll just need to enter it with the 5 hour variation. otherwise if you are using something like date() or now() within a mysql query, it will use whatever the local time on the server is.
i am using getdate()
Posted: Wed Jul 17, 2002 12:52 pm
by mike
i am using getdate() so is their no way of it adding 5 hours to what the getdate recieves?
thanks
mike
Posted: Wed Jul 17, 2002 1:31 pm
by llimllib
Code: Select all
$today = getdate();
$hour = $todayї'hours'] + 5;
if($hour > 23)
$hour = $hour - 24;
echo $hour;
thanks but....
Posted: Wed Jul 17, 2002 4:11 pm
by mike
ok that works very well mate but.....
when the time is pushed 5 hours forward and into the next day the date isnt moving forward one--- how do i make it do that?-- this is the code as it is now (which works

)
$date = getdate();
$mday = $date['mday'];
$mon = $date['mon'];
$year = $date['year'];
$today = getdate();
$hour = $today['hours'] + 5;
if($hour > 23)
$hour = $hour - 24;
echo $hour;
$minutes = $date['minutes'];
thanks for all help
mike
Posted: Wed Jul 17, 2002 11:49 pm
by llimllib
That's where you get to do the fun part of programming. If you move the hour back 23, move the day up 1. If the day was 31, it's now 1 - figure out the logic. Practice this type of simple logic, and the simple things will start to come easier. Peace
Posted: Thu Jul 18, 2002 12:05 am
by will
actually, the easiest thing would probably be to convert the date to "seconds since epoch" using mktime(). then add 1800 (60 * 60 * 5), and then convert it back to whatever format you want using date(). this way the date function will handle all of the dirty work (last day of month, etc).
er.....
Posted: Thu Jul 18, 2002 3:45 am
by mike
guys you both completely lost me their :S
I understand what you are saying but have no idea what so ever how to put that into code!
thats why I am here!
mike
Posted: Thu Jul 18, 2002 5:51 am
by will
ok, if you're just using the current time (plus 5 hours of course), then try this....
Code: Select all
// get UNIX timestamp (number of seconds since epoch)
$current_time = time();
// add 5 hours. 5 hours * 60 minutes * 60 seconds = 18000
$adjusted_time = $current_time + 18000;
// at this point, it depends on your database field type. if you have date
// field, you would use this
$formatted_time = date('Y-m-d', $adjusted_time);
// if you are storing the epoch formatted time in the database (such as
// in a bigint field), then you don't need to change anything
$formatted_time = $adjusted_time;
// then just insert this into your database
mysql_query("INSERT into news SET date=$formatted_time");
let me know if any of that is unclear.