我有一个按钮"保存"和一个文本框,其中填充了当前日期的值(以 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."
不知道你对输出you're in a new month
的确切要求是什么,这就是我得到的
$time = strtotime('2015-02-01');
//Change the string literal to your $_POST variable
if((int)date('j',$time)==1){
echo "The month of ". date('Y-m-01',$time-1)." has passed";
}else{
echo "Current month, nevermind";
}
让我知道您的要求是什么,希望我可以帮助您解决这个问题。在这种情况下,真的不需要MySQL。