justinede Posted August 22, 2008 Share Posted August 22, 2008 Hey when a user logs out, the time they logged out is added to my database, but in the database it just looks like a bunch of numbers. Here is me logout script. $time = time(); //// now... // mjr start - start session to get saved myusername session_start(); $sql = "UPDATE members SET timeout = '$time' WHERE username = '" . $_SESSION['myusername'] . "'"; mysql_query($sql)or die(mysql_error()); // mjr end session_unset(); session_destroy(); // Logged out, return home. Header("Location: index.php"); ?> So anyone know how to make it into a time and date format? Link to comment https://forums.phpfreaks.com/topic/120909-solved-reading-time-in-database/ Share on other sites More sharing options...
pocobueno1388 Posted August 22, 2008 Share Posted August 22, 2008 It's because your using a timestamp. Change the "timeout" field type to datetime. Then when you do your query, just use the NOW() function. UPDATE members SET timeout = NOW() WHERE username = '" . $_SESSION['myusername'] . "' Link to comment https://forums.phpfreaks.com/topic/120909-solved-reading-time-in-database/#findComment-623254 Share on other sites More sharing options...
_absurd Posted August 22, 2008 Share Posted August 22, 2008 Yeah, time() "returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)" Link to comment https://forums.phpfreaks.com/topic/120909-solved-reading-time-in-database/#findComment-623256 Share on other sites More sharing options...
justinede Posted August 22, 2008 Author Share Posted August 22, 2008 ok so in the database, i can have timeout be a VARCHAR 225 or a special thing? Link to comment https://forums.phpfreaks.com/topic/120909-solved-reading-time-in-database/#findComment-623262 Share on other sites More sharing options...
Prismatic Posted August 22, 2008 Share Posted August 22, 2008 Personally I would just make timeout DATETIME, then run the query like so, $sql = "UPDATE members SET timeout = FROM_UNIXTIME(". time() .") WHERE username = '" . $_SESSION['myusername'] . "'"; The current date and time is now in the database in the form of YYYY-MM-DD HH:MM:SS Then the query to select it would be something like this, $query = mysql_query("SELECT *, UNIX_TIMESTAMP(timeout) AS timeout FROM members WHERE username = 'bleh'"); timeout is now a timestamp which you can format with date $row = mysql_fetch_array($query); echo date("m/d g:i a", $row['timeout']); Would produce a string like 08/20 5:40 am Link to comment https://forums.phpfreaks.com/topic/120909-solved-reading-time-in-database/#findComment-623270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.