jeger003 Posted January 17, 2009 Share Posted January 17, 2009 im using a script i purchased and the dates are stored like this 1230696669 and this is some date in December of 08. how do i make it display correctly cause i need to call the dates and display to the user. maybe display it like Dec. 25 2008? Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/ Share on other sites More sharing options...
.josh Posted January 17, 2009 Share Posted January 17, 2009 That format is a unix timestamp. It's your date stored as the number of seconds since the beginning of time. Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/#findComment-738857 Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2009 Share Posted January 17, 2009 And to format it any way you want in a query use the mysql FROM_UNIXTIME() function with the second format parameter to give you the format you want - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_from-unixtime Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/#findComment-738858 Share on other sites More sharing options...
jeger003 Posted January 17, 2009 Author Share Posted January 17, 2009 And to format it any way you want in a query use the mysql FROM_UNIXTIME() function with the second format parameter to give you the format you want - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_from-unixtime thank you guys for the help. I didnt know any of this. PFMaBiSmAd thank you for the link. I went over the page and i cant really tell where or how i use it. i mean here is what i want to display, how do i use it with something like this? after $query = mysql_query("SELECT name, location, date FROM users_table"); //would this work? $query = mysql_query("SELECT name, location, date FROM users_table"); FROM_UNIXTIME(date,YYYYMMDDHHMMSS.uuuuuu); Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/#findComment-738866 Share on other sites More sharing options...
448191 Posted January 17, 2009 Share Posted January 17, 2009 //would this work? Sure. Ok, maybe not. I guess it depends. Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/#findComment-738879 Share on other sites More sharing options...
jeger003 Posted January 17, 2009 Author Share Posted January 17, 2009 //would this work? Sure. Ok, maybe not. I guess it depends. lol oh that definitely solved my problem. Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/#findComment-738880 Share on other sites More sharing options...
chronister Posted January 17, 2009 Share Posted January 17, 2009 That format is a unix timestamp. It's your date stored as the number of seconds since the beginning of time. Sorry CV for correcting you. You may have meant this but it is not since the beginning of time... it is seconds elapsed since January 1, 1970 00:00:00 (UNIX epoch) not including leap seconds. Which is why you may frequently see a screwed up date revert to 12/31/1969. http://en.wikipedia.org/wiki/Unix_time And since it it not mentioned yet, the PHP function date() will format the string for you as well. If your pulling it from MySQL, your better off letting the SQL Server do the work for you, but date works like this <?php echo date('m/d/y H:i:s','1230696669 '); // prints 12/30/08 22:11:09 ?> Nate Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/#findComment-738970 Share on other sites More sharing options...
.josh Posted January 17, 2009 Share Posted January 17, 2009 Sorry CV for correcting you. You may have meant this but it is not since the beginning of time... it is seconds elapsed since January 1, 1970 00:00:00 (UNIX epoch) not including leap seconds. Which is why you may frequently see a screwed up date revert to 12/31/1969. Buzz kill. It was both a joke and a simplified explanation, as I figured saying all that to the OP would roughly translate to "It's your date stored as the number of seconds since blah blah blah analretentivewhywon'tthisguyshutup moreblah wtfdoesallthatmeananywayz lolzblahblah". Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/#findComment-738979 Share on other sites More sharing options...
Mchl Posted January 17, 2009 Share Posted January 17, 2009 That format is a unix timestamp. It's your date stored as the number of seconds since the beginning of time. Sorry CV for correcting you. You may have meant this but it is not since the beginning of time... it is seconds elapsed since January 1, 1970 00:00:00 (UNIX epoch) Well... it IS beginning of time, isn't it? Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/#findComment-738993 Share on other sites More sharing options...
jeger003 Posted January 17, 2009 Author Share Posted January 17, 2009 That format is a unix timestamp. It's your date stored as the number of seconds since the beginning of time. Sorry CV for correcting you. You may have meant this but it is not since the beginning of time... it is seconds elapsed since January 1, 1970 00:00:00 (UNIX epoch) not including leap seconds. Which is why you may frequently see a screwed up date revert to 12/31/1969. http://en.wikipedia.org/wiki/Unix_time And since it it not mentioned yet, the PHP function date() will format the string for you as well. If your pulling it from MySQL, your better off letting the SQL Server do the work for you, but date works like this <?php echo date('m/d/y H:i:s','1230696669 '); // prints 12/30/08 22:11:09 ?> Nate lol...you guys are great! thanks for the help Nate. It works great!! this is what i did if anyone needs it in the future: $query = 'SELECT date FROM listings'; $check_query = mysql_query($query) or die(mysql_error()); $fetch_data = mysql_fetch_array($check_query); $fetch_date = $fetch_data['date']; echo date('m/d/y H:i:s', $fetch_date); Thanks Again Everyone!! Quote Link to comment https://forums.phpfreaks.com/topic/141160-solved-why-are-dates-stored-in-my-mysql-db-in-a-weird-way/#findComment-739156 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.