phpretard Posted May 28, 2009 Share Posted May 28, 2009 I know this is probable an easy question but, What is the best way to display "2009-05-27 20:35:18" as this "05-27-2009"? Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 28, 2009 Share Posted May 28, 2009 explode on the ' ' character. You'll get two strings -- the first one is the one you want. Quote Link to comment Share on other sites More sharing options...
phpretard Posted May 28, 2009 Author Share Posted May 28, 2009 Exploding is something I am still working on (literally and metaphorically). Any pointers? Quote Link to comment Share on other sites More sharing options...
phpretard Posted May 28, 2009 Author Share Posted May 28, 2009 I have it as "2009-05-27" no minutes or seconds I just need to rearrange a little Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 28, 2009 Share Posted May 28, 2009 If the original value is in a database, you can use the mysql DATE_FORMAT() function in your SELECT query to give you the date in any format you want. Quote Link to comment Share on other sites More sharing options...
phpdragon Posted May 28, 2009 Share Posted May 28, 2009 $startdate="2009-05-27 20:35:18"; $predate=explode(' ', $startdate); $splitdate=explode('-', $predate[0]); $newdate="$splitdate[2]-$splitdate[1]-$splitdate[0]"; echo $newdate; Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 28, 2009 Share Posted May 28, 2009 <?php $time = '2009-05-27 20:35:18'; $pieces = explode(' ', $time); echo $pieces[0]; Or in SQL SELECT DATE_FORMAT(`date_column`, '%Y-%m-%d') AS `date` Quote Link to comment Share on other sites More sharing options...
phpdragon Posted May 28, 2009 Share Posted May 28, 2009 sorry with my result switch $splitdate[2] and $splitdate[1] around to have the way you first described 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.