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? Link to comment https://forums.phpfreaks.com/topic/96486-date-format-issue-says-1970-always/ 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. Link to comment https://forums.phpfreaks.com/topic/96486-date-format-issue-says-1970-always/#findComment-493795 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 Link to comment https://forums.phpfreaks.com/topic/96486-date-format-issue-says-1970-always/#findComment-493801 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 Link to comment https://forums.phpfreaks.com/topic/96486-date-format-issue-says-1970-always/#findComment-493912 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.