2013-04-22 53 views

回答

8

使用PHP'sdate功能

date("Y-m-d",strtotime("19th April 2013")); 
+0

感謝,如果我想在此日期17/04/2013至2013年4月17日轉換???? – 2013-04-22 05:02:40

1

您仍然可以通過查詢做到這一點,所以你不會對PHP側任何轉換。由於該列的數據類型是字符串,因此需要使用STR_TO_DATE將其轉換爲有效日期。

SELECT DATE_FORMAT(STR_TO_DATE(columnname, '%D %M %Y'), '%Y-%m-%d') new_format 
FROM TableName 
1

下面的PHP代碼轉換的時間爲所需的格式

$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'])); 
2

個是下面的代碼更改日期格式

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