ukscotth Posted December 1, 2008 Share Posted December 1, 2008 Hi, I think this should be pretty easy for someone who knows how. I have a date and time stored in a database field and when i do a simple echo it shows up like this : 1224950428 Is there an easy way i can make it display something like this instead : 23 March, 8:45pm Many thanks in advance. Scott. Link to comment https://forums.phpfreaks.com/topic/135056-changing-the-date-format-of-a-variable/ Share on other sites More sharing options...
wildteen88 Posted December 1, 2008 Share Posted December 1, 2008 Yes use the date function Link to comment https://forums.phpfreaks.com/topic/135056-changing-the-date-format-of-a-variable/#findComment-703452 Share on other sites More sharing options...
ukscotth Posted December 1, 2008 Author Share Posted December 1, 2008 tried that but not sure where to put the actual variable where the date is stored. Would it be something like this ? <?php echo date ($topic['topic_last_post']); ?> Link to comment https://forums.phpfreaks.com/topic/135056-changing-the-date-format-of-a-variable/#findComment-703455 Share on other sites More sharing options...
wildteen88 Posted December 1, 2008 Share Posted December 1, 2008 $last_post_date = date("F j, Y, g:i a", $topic['topic_last_post'])); echo $last_post_date Link to comment https://forums.phpfreaks.com/topic/135056-changing-the-date-format-of-a-variable/#findComment-703459 Share on other sites More sharing options...
ukscotth Posted December 1, 2008 Author Share Posted December 1, 2008 sorted. Thanks alot for ur help, ur a star most appreciated. Link to comment https://forums.phpfreaks.com/topic/135056-changing-the-date-format-of-a-variable/#findComment-703462 Share on other sites More sharing options...
DjMikeWatt Posted May 3, 2009 Share Posted May 3, 2009 Would this be the same as: <?php $event_date = date("F j, Y", ($row_rs_user['event_date'])); echo $event_date ; ?> I ask because when I use the above code, the date displays as "December 31, 1969" even though the DB data is "2009-10-21"... Obviously, I am expecting the page to echo "October 21, 2009", but this is not what I'm getting... Any thoughts on what I've done wrong? Link to comment https://forums.phpfreaks.com/topic/135056-changing-the-date-format-of-a-variable/#findComment-824719 Share on other sites More sharing options...
trq Posted May 3, 2009 Share Posted May 3, 2009 date expects a unix timestamp. You'll need to convert your string to one if you expect it to work. <?php $event_date = date("F j, Y", strtotime($row_rs_user['event_date'])); echo $event_date; ?> Link to comment https://forums.phpfreaks.com/topic/135056-changing-the-date-format-of-a-variable/#findComment-824720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.