php date format
I have a date in a variable like: 01-01-2009开发者_开发技巧 and need to change the format to Y-m-d. What should I use to do this conversion?
You can use the strtotime
and date
functions like this:
$str = '01-01-2009';
$date = date('Y-m-d', strtotime($str));
echo $date; //2009-01-01
To convert the date format from dd-mm-yyyy to yyyy-mm-dd in php,
<?php
$dt='01-01-2009';
$dt=date('Y-m-d',strtotime($dt));
echo $dt;
?>
The o/p will be, 2009-01-01
精彩评论