我在数据库中有这个日期格式
19th April 2013
我想将它转换为
2013-04-19
我使用了if,else条件语句,但它变得太长且复杂。是否有任何内置函数可以使用?
date("Y-m-d",strtotime("19th April 2013"));
date("Y-m-d",strtotime("19th April 2013")); to get as 2013-04-19
对于第二个问题
date("Y/m/d",strtotime("17th April 2013")); to get as 2013-04-17
您仍然可以通过查询来执行此操作,因此不会在PHP
端进行任何转换。由于列的数据类型为字符串,您需要使用STR_TO_DATE
将其转换为有效日期。
SELECT DATE_FORMAT(STR_TO_DATE(columnname, '%D %M %Y'), '%Y-%m-%d') new_format
FROM TableName
$date = '19th April 2013'
echo date('Y-m-d', strtotime($date));
April 22, 2013 date("F d, Y",strtotime($myrow['date']));
Monday, April 22, 2013 date("l, F d, Y",strtotime($myrow['date']));
Apr 22, 2013 date("M d, Y",strtotime($myrow['date']));
22 April 2013 date("d F Y",strtotime($myrow['date']));
22 Apr 2013 date("d M Y",strtotime($myrow['date']));
Mon, 22 Apr 2013 date("D, d M Y",strtotime($myrow['date']));
Monday, the 22nd of April, 2013 date("l",strtotime($myrow['date'])) . ", the " . date("jS",strtotime($myrow['date'])) . " of " . date("F, Y",strtotime($myrow['date']));