wmguk Posted March 17, 2008 Share Posted March 17, 2008 Hey, I am trying to format a date, its not a timestamp, basically you select the day, month and year from a drop down and its put in to the database in 3 seperate fields.. so if i do $datef = "$date_day"."$date_month"."$date_year" ; then echo $datef it displays right (17082007) now i try and format the output, and its wrong.. $date = date("jS F Y", $datef); i get 17th February 1970 any ideas? Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted March 17, 2008 Share Posted March 17, 2008 date() wants a UNIX timestamp, which is the number of seconds since January 1, 1970. You can use mktime() to make a UNIX timestamp using the day, month, and year (and minutes, seconds, and hours if you want). This is how you use it: $date = date("jS F Y", mktime(0, 0, 0, $date_month, $date_day, $date_year)); The three zeros at the beginning are the hours, minutes, and seconds. Quote Link to comment Share on other sites More sharing options...
wmguk Posted March 17, 2008 Author Share Posted March 17, 2008 Ah!! of course!! thank you, I was getting so confused, I knew when I saw 1970 that something was wrong in the formatting, but I just couldnt work it out! Excellent, thank you Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 17, 2008 Share Posted March 17, 2008 Or you can use the strtotime() function: <?php $date = date('jS F Y',strtotime($date_year . '-' . $date_month . '-' $date_day); ?> Ken Quote Link to comment 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.