我有一个“保存”按钮和一个文本框,其中填充了 php 中当前日期的值。
用户按下保存按钮后,我的 php 脚本必须检查上个月是否已经过去。例如:
文本框值 = '2015-02-01'(假设现在是当前日期),
然后用户单击“保存”按钮。
我的 php 脚本必须说“2015-01-01”日期已经过去,而您的日期是“2015-02-01”月份。 我真的认为我的 if 条件是:
//if a month has passed,
# echo "Your in the new month";
//else
# echo "Your still in this month";
我认为这与此查询有关:
"SELECT SUBDATE('$currentDate', INTERVAL 1 MONTH) AS prevMonth";
但是我怎样才能完成它并将其应用到我的 php 中的条件中?这里真的需要帮助。谢谢
最佳答案
我会在 PHP 中而不是 MySQL 中执行此操作:
<?php
// Compare mysql result in Y-m format to input in same format
if (date('Y-m', strtotime($mysqlResult)) < date('Y-m', strtotime($textboxValue)))
echo "You're in the new month (" . date('m') . ")";
else
echo "You're still in this month."
关于php - 如何在mysql和php中检查上个月是否已经过去?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27957416/