datetime仅返回日期 [英] datetime only returning date

查看:95
本文介绍了datetime仅返回日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中列日期设置为datetime。当我返回并从行中获取日期时,它仅返回日期而不是时间。

I have a table with column date set to datetime. When i return and get the date from row it is only returning the date and not the time.

 $date = $row["date"];

我尝试格式化如下,但出现错误:

I have tried to format as below and I get the error of:

警告:date_format()期望参数1为DateTime,字符串给定

Warning: date_format() expects parameter 1 to be DateTime, string given

 $date = date_format($row["date"], 'Y-m-d H:i:s');

如何获取全部值?

推荐答案

在您的select语句中,将日期转换为datetime。例如,

in your select statement, cast the date into datetime. ex

SELECT CAST(date AS DATETIME) newDate

并将其检索为

$dateTime = strtotime($row["newDate"]);

这篇关于datetime仅返回日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆