the_oliver Posted March 18, 2007 Share Posted March 18, 2007 Hello, I have a date field in MySQL database. I have to enter the date in this format: YYYY-MM-DD so i can have the search results ordered by date. I would however like it displaid in the uk date format DD-MM-YYYY. How can i go about this? Thanks! Link to comment https://forums.phpfreaks.com/topic/43235-solved-uk-not-us-date/ Share on other sites More sharing options...
trq Posted March 18, 2007 Share Posted March 18, 2007 Take a look at the date function. Link to comment https://forums.phpfreaks.com/topic/43235-solved-uk-not-us-date/#findComment-209923 Share on other sites More sharing options...
the_oliver Posted March 20, 2007 Author Share Posted March 20, 2007 Ok, so i have go that $today = date("F j, Y"); echo $today; will give me the format October 15, 2006. But i want to do this of a result stored in a database. So i tried: $time = 2007-03-07; $today = date("F j, Y", $time); echo $today; (as 2007-03-07 is the format stored in the database) But that gives me January 1, 1970 not March 7, 2007. Where have i gone wrong?? Thanks. Link to comment https://forums.phpfreaks.com/topic/43235-solved-uk-not-us-date/#findComment-211237 Share on other sites More sharing options...
kenrbnsn Posted March 20, 2007 Share Posted March 20, 2007 The second parameter to the date() function is a UNIX time stamp, so you have to convert the date string to that. The easiest way is to use the strtotime() function. <?php $time = 2007-03-07; $today = date("F j, Y", strtotime($time)); echo $today; ?> Ken Link to comment https://forums.phpfreaks.com/topic/43235-solved-uk-not-us-date/#findComment-211252 Share on other sites More sharing options...
the_oliver Posted March 20, 2007 Author Share Posted March 20, 2007 Thanks! Sorted it! Link to comment https://forums.phpfreaks.com/topic/43235-solved-uk-not-us-date/#findComment-211295 Share on other sites More sharing options...
mjlogan Posted March 20, 2007 Share Posted March 20, 2007 Side Note: Store it as a timestamp, and you can easily work with it and format it how you want. Link to comment https://forums.phpfreaks.com/topic/43235-solved-uk-not-us-date/#findComment-211302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.