...

View Full Version : Date



cozzy1984
03-15-2008, 01:31 AM
Got my website almost complete but hvaing problems deciding what to do with the Date and the way to manage the timestamps in the mysql database. The server seems to be +2hrs and as most of my timestamps or updated on current by the database, ive been trying to convert the timestamps -2hrs.

Only problem is im trying to get the timestamp from the database -2hrs and display it in the correct format.


while($lastactive_row = @mysql_fetch_array($lastactive_result))
{
$lastactive_username = $lastactive_row["username"];
$lastactive_date = date("d M y H:i", strtotime($lastactive_row["last_active"]));

just dont know the best way to do this, i thought that it was just a matter of adding -2hours before or after $lastactive_row["last_active"] but its not working.

Any ideas?

Inigoesdr
03-15-2008, 01:39 AM
What time format is $lastactive_row['last_active'] in(Unix timestamp, MySQL DATETIME, etc.)?

If the code you have now is showing the time +2hours you should be able to use this:

$lastactive_date = date('d M y H:i', strtotime($lastactive_row['last_active']) - 7200);

oesxyl
03-15-2008, 01:44 AM
Got my website almost complete but hvaing problems deciding what to do with the Date and the way to manage the timestamps in the mysql database. The server seems to be +2hrs and as most of my timestamps or updated on current by the database, ive been trying to convert the timestamps -2hrs.
Only problem is im trying to get the timestamp from the database -2hrs and display it in the correct format.


while($lastactive_row = @mysql_fetch_array($lastactive_result))
{
$lastactive_username = $lastactive_row["username"];
$lastactive_date = date("d M y H:i", strtotime($lastactive_row["last_active"]));

just dont know the best way to do this, i thought that it was just a matter of adding -2hours before or after $lastactive_row["last_active"] but its not working.

Any ideas?
-2 hours are now, later could be -3 or -1 hours, that depend of server and yours settings. You must deal with local time and universal time, zonetime and day light saving, depend.
After you solve this the code is not a problem, until then anything you do is a improvisation that could work for a short time.

best regards

Inigoesdr
03-15-2008, 01:51 AM
You can also use the date_default_timezone_set() (http://php.net/date_default_timezone_set) (PHP 5 >= 5.1.0) to set the default timezones used for all date/time functions.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum