MKTIME,PHP 日期/时间戳 YYYY-MM-DD

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2829120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:47:34  来源:igfitidea点击:

MKTIME, PHP date/timestamp YYYY-MM-DD

phpmktime

提问by Mikey1980

I need to query MySQL for the current date (from PHP) in YYYY-MM-DDformat... anyone?

我需要以YYYY-MM-DD格式查询 MySQL 的当前日期(来自 PHP)......有人吗?

回答by Sarfraz

MySQL curdate:

MySQL curdate

You can do in query:

您可以在查询中执行以下操作:

select curdate()

PHP date

PHP date

echo date('Y-m-d');

If you want to pass your own date format:

如果要传递自己的日期格式:

echo date('Y-m-d', strtotime($your_date));

回答by Mitch Dempsey

date("Y-m-d")should give you the current date in that format.

date("Y-m-d")应该以该格式为您提供当前日期。

回答by Jon

SELECT CURDATE();

SELECT CURDATE();

回答by Joe Mills

The function I think you are looking for is

我认为你正在寻找的功能是

$datetime = strtotime($MySQLDateResponse);

$MySQLDatResponse being the date you get back from MySQL. This will give you a PHP time stamp. You can then convert that timestamp into any date format you want. For the one you listed it's

$MySQLDatResponse 是您从 MySQL 返回的日期。这会给你一个 PHP 时间戳。然后,您可以将该时间戳转换为您想要的任何日期格式。对于你列出的那个

date("Y-m-d", $datetime);

Hope that helps

希望有帮助