[英]Change mysql number to date format in php
I have a database the holds values for months and days as integers. 我有一个数据库,数月和日的保持值为整数。 For instance June 25th is (month column) 6 and (day column) 25. I have a place on a website I would like the display to be June 25th instead of 6 25. Without writing a case statement is there a way with php's built in date functions to do this?
例如,6月25日是(月份列)6和(日列)25。我在网站上有一个地方我希望显示的是6月25日而不是6月25日。没有写一个案例陈述是有一种方法与PHP的内置在日期功能这样做?
There's a few ways to do this. 有几种方法可以做到这一点。 One example using
date()
: 使用
date()
一个例子:
echo date("F jS", strtotime($row['month'].'/'.$row['day']));
Another using DateTime
: 另一个使用
DateTime
:
$date = DateTime::createFromFormat("n/j", $row['month'].'/'.$row['day']);
echo $date->format("F jS");
Another directly in MySQL (untested): 另一个直接在MySQL(未经测试):
SELECT DATE_FORMAT(UNIX_TIMESTAMP('2012-',month,'-',day), "%M %D") AS the_date
echo date('l \t\h\e jS');
这必须这样做
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.