我将MySQL表中的日期存储为yyyy-mm-dd(或典型的MySQL'日期'格式)。我怎样才能知道到那时剩下多少整天?
例如,如果我有:
2011-03-05
它会说:
17 More Days
答案 0 :(得分:2)
在PHP中:
$days = (strtotime($date) - time()) / 86400;
在MySQL中:
SELECT
((UNIX_TIMESTAMP(date) - UNIX_TIMESTAMP()) / 86400) AS days
FROM table;
或者@coreyward声明(在MySQL中):
SELECT
DATEDIFF(UNIX_TIMESTAMP(date,NOW()) AS days
FROM table;
答案 1 :(得分:1)
在PHP 5中 - 日期DIFF
http://php.net/manual/en/function.date-diff.php
您需要: (PHP 5> = 5.3.0)
如果没有,您可以使用此功能:
<?php
$today = strtotime("2011-02-03 00:00:00");
$myBirthDate = strtotime("1964-10-30 00:00:00");
printf("I'm %d days old.", round(abs($today-$myBirthDate)/60/60/24));
?>
答案 2 :(得分:0)
尝试其中一个几乎相同的问题:
PHP: How to count days between two dates in PHP?
MySQL的: How to get the number of days of difference between two dates on mysql?