steven121 Posted November 24, 2009 Share Posted November 24, 2009 I am having trouble formating my date. I have saved the date of post into the database and it is saved as 2009-11-24. When i pull the date out i am trying to format this into November 24th 2009 however using the following code i dont get any errors but my date is January 1, 1970 $last_post_date = date("F jS, Y", $row['blogDate']); echo $last_post_date; Can anyone help me? Link to comment https://forums.phpfreaks.com/topic/182762-problems-with-date-function/ Share on other sites More sharing options...
c-o-d-e Posted November 24, 2009 Share Posted November 24, 2009 Try this under your last echo. echo ''.$row['blogDate'].''; What is the value? Link to comment https://forums.phpfreaks.com/topic/182762-problems-with-date-function/#findComment-964595 Share on other sites More sharing options...
steven121 Posted November 24, 2009 Author Share Posted November 24, 2009 Value to that echo is 2009-11-24 Link to comment https://forums.phpfreaks.com/topic/182762-problems-with-date-function/#findComment-964597 Share on other sites More sharing options...
c-o-d-e Posted November 24, 2009 Share Posted November 24, 2009 Are you using the date function just to give you "November 24 2009" ? How are you defining whats going into blogDate ? Link to comment https://forums.phpfreaks.com/topic/182762-problems-with-date-function/#findComment-964602 Share on other sites More sharing options...
steven121 Posted November 24, 2009 Author Share Posted November 24, 2009 I am setting a variable of date as follows $date = date("Y/m/d"); This is then used to insert into the database and saves as 2009-11-24 format i am then tring to take this and reformat it to read November 24th 2009 on any page that is required. Link to comment https://forums.phpfreaks.com/topic/182762-problems-with-date-function/#findComment-964608 Share on other sites More sharing options...
Yesideez Posted November 24, 2009 Share Posted November 24, 2009 Try this... $last_post_date = date("F jS, Y", strtotime($row['blogDate'])); Link to comment https://forums.phpfreaks.com/topic/182762-problems-with-date-function/#findComment-964613 Share on other sites More sharing options...
steven121 Posted November 24, 2009 Author Share Posted November 24, 2009 That worked a treat, thanks mate. Link to comment https://forums.phpfreaks.com/topic/182762-problems-with-date-function/#findComment-964617 Share on other sites More sharing options...
Yesideez Posted November 24, 2009 Share Posted November 24, 2009 The reason is because date() expects an integer as the second parameter - a UNIX time stamp - you were passing it a DATE string so you needed to use strtotime() to convert it first. Link to comment https://forums.phpfreaks.com/topic/182762-problems-with-date-function/#findComment-964623 Share on other sites More sharing options...
c-o-d-e Posted November 24, 2009 Share Posted November 24, 2009 I was just about to suggest that. or convert it to strtotime before inputting it into the database. Link to comment https://forums.phpfreaks.com/topic/182762-problems-with-date-function/#findComment-964626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.