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! Quote Link to comment Share on other sites More sharing options...
trq Posted March 18, 2007 Share Posted March 18, 2007 Take a look at the date function. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
the_oliver Posted March 20, 2007 Author Share Posted March 20, 2007 Thanks! Sorted it! Quote Link to comment 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. 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.