php - 在 PHP 中的日期格式之间转换给出错误

标签 php mysql date datetime calendar

<分区>

我检索的数据库日期格式是

 $event_date='2013-01-20';

我想将这种格式转换成这样 2013-01-01

我试过了

echo date('M d, Y',$event_date)
//but it is printing wrong value "Jan 01, 1970"

并给出错误:注意 (8):遇到格式不正确的数值

如果有人能捕获请帮助我获得正确的值(value)

最佳答案

您将需要使用 strtotime()函数正确格式化日期,因为 date() 函数需要第二个参数是时间戳

echo date('M d, Y',strtotime($event_date));

来自文档

The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.

现场工作样本 here

关于php - 在 PHP 中的日期格式之间转换给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22168770/

相关文章:

php - 32 位 Linux 和 PHP < 7 上的 MongoClient,无需重构

php - 首先匹配精确然后在类似查询 mysql laravel-5 中的相关数据

php - 如何将 MySQL 查询 MATCH/AGAINST 转换为 LIKE 以绕过停用词列表

mysql - 错误 1175 : Delete rows from table1 where PK matches PK from table2

MYSQL 根据特定列选择多列

javascript - 如何从日期字符串格式获取日期对象

Java:如何创建适用于我的日期类的方法

PHP:检查图像质量/像素化的代码(不是压缩率而是真实质量)?

mysql - bitnami 服务器 AWS EC2 micro 上的性能不佳

javascript - Angular – 通过重复过滤过去和 future 的事件