如何格式化来自MYSQL的日期 [英] how to format date coming from MYSQL
本文介绍了如何格式化来自MYSQL的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单的问题,但我需要它:)
Simple question but i need it :)
$query = "SELECT *
FROM `set`
WHERE ID = '$id'";
$result = mysql_query($query);
$info = mysql_fetch_assoc($result);
$frmdate = $info['date'];
到目前为止我试过
$timestamp = strtotime($info['date']);
$joined_date = date("j M. Y", $timestamp);
但没有运气!
日期mysql中的字段是DATE数据类型
"date" field in mysql is DATE data type
我想让它像2009年10月23日
I want to make it like "23 Oct. 2009"
我如何做?
谢谢
推荐答案
strtotime
要将日期的字符串表示形式转换为时间戳,则可以使用 日期
将时间戳转换为您喜欢的任何格式:
You can use strtotime
to convert the string representation of the date into a timestamp then you can use date
to convert the timestamp into whatever format you like:
$timestamp = strtotime($frmdate);
$formatted_date = date("j M. Y", $timestamp);
您还可以将yyyy-mm-dd格式的转换移动到时间戳到查询本身,使用:
You can also move the translation from the yyyy-mm-dd format to timestamp into the query itself, using:
select unix_timestamp(field_name) as field_name_timestamp
这篇关于如何格式化来自MYSQL的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文