jwwceo Posted December 17, 2007 Share Posted December 17, 2007 I have a variable in date format YYYY-MM-DD. How do I parse out the YYYY, the MM, and the DD so I can use them on their own??? James Quote Link to comment Share on other sites More sharing options...
fert Posted December 17, 2007 Share Posted December 17, 2007 http://us2.php.net/manual/en/function.strtotime.php Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2007 Share Posted December 17, 2007 $date = '2007-12-16'; preg_match('/(\d{4})-(\d{2})-(\d{2})/',$date,$date_parts); This puts the year, month, and day $date_parts[1] through $date_parts[3]. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 17, 2007 Share Posted December 17, 2007 You can use strtotime() in conjunction with the date() function, or you can just explode the string on "-" and assign the the exploded segments to variables. <?php $date = '2007-12-16'; list($year,$month,$day) = explode('-',$date); echo 'Year: ' . $year . "<br>\n"; echo 'Month: ' . $month . "<br>\n"; echo 'Day: ' . $day . "<br>\n"; ?> Ken 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.