Posted 20 March 2006 - 06:50 PM
I have a date like, 2006-03-19 16:42:01 and I would like to "convert" it into something like...
$year = "2006";
$month = "03";
$day = "19";
I don't need the time at all. I just need the year, month, and day from that long string into some variables so I can pull data from the MySQL server correctly.
I was guessing that I could use a trim of some sort, but is this the best way?
I cannot change the long date format above because it is already in wide spread use on the site.
Thank you in advance to anyone who can help.
Posted 20 March 2006 - 07:08 PM
<?php $long_date_time = "2006-03-19 16:42:01"; $short_date = date('Y-m-d',strtotime($long_date_time)); echo $long_date_time.'<br>'.$short_date; ?>
Posted 20 March 2006 - 07:28 PM
Posted 20 March 2006 - 08:13 PM
Thank you very much, that solves a big part of the problem. Now that the time is removed, I can work on getting the parts into their variables correctly.
easiest way to do that that i know of is like so:
$date = "2006-03-20"; list($year, $month, $day) = explode("-", $date); echo "$year<br />\n"; echo "$month<br />\n"; echo "$day<br />\n";
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users