adamwhiles Posted June 27, 2006 Share Posted June 27, 2006 I have a field in my database that holds a date like so: 2006-06-23I want to convert that with php so I can print it out like this: June 23, 2006I need to keep the format of the date in the table because it needs to be 2006-06-23 due to another script that uses the date in that format.So how can i use PHP to pull the date out of the database and convert it to the longer format? Link to comment https://forums.phpfreaks.com/topic/13053-date-conversion/ Share on other sites More sharing options...
thepip3r Posted June 27, 2006 Share Posted June 27, 2006 easy:[code]$oldDate = '2006-06-23';$answer = date('F d, Y',strtotime(date('Y-m-d',$oldDate)));[/code]so ur taking the old date, converting it to a unix timestamp, then reformatting it to how you want to see it.FYI - it's easier just to start out with the Unix timestamp in the DB. =D Link to comment https://forums.phpfreaks.com/topic/13053-date-conversion/#findComment-50222 Share on other sites More sharing options...
adamwhiles Posted June 27, 2006 Author Share Posted June 27, 2006 I think I may do that, change the field to a unix time stamp, is there a certain type of field type it needs to be in mysql? Right now the field type is DATE, i know DATE won't work for unix time stamp, so what should it be?Thanks Link to comment https://forums.phpfreaks.com/topic/13053-date-conversion/#findComment-50230 Share on other sites More sharing options...
adamwhiles Posted June 28, 2006 Author Share Posted June 28, 2006 I used the code exactly as you put it, now all my dates are showing like this:December 31, 1969What happened? Link to comment https://forums.phpfreaks.com/topic/13053-date-conversion/#findComment-50307 Share on other sites More sharing options...
adamwhiles Posted June 28, 2006 Author Share Posted June 28, 2006 Finally figured it out, here is the finally working code for future reference:[code]$oldDate = '2006-06-23';$answer = date('F d, Y',strtotime($oldDate));[/code] Link to comment https://forums.phpfreaks.com/topic/13053-date-conversion/#findComment-50311 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.