php日期比较问题
你好,我在比较日期时遇到一些麻烦。
在我的 php 验证脚本中,这是客户的生日。
$bdate = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
这是今天的日期:
$cdate = date("Y-m-d");
这是验证部分:
if($bdate > $cdate)
{
die('{status:0,txt:"Please check your birthday"}');
}
当生日年份和今天的年份不同(例如与 2011 年不同)时,它会起作用。 但是,当生日年份和今天的年份相同(均为 2011 年)时,验证部分无法将它们与日期进行比较。 例子, 如果 $bdate 是 2011-01-01 $cdate is 2011-05-31
if($bdate > $cdate)
{
die('{status:0,txt:"Please check your birthday"}');
}
返回 true。
需要帮助。
hello I have some trouble with comparing dates.
in my php validation script, this is the client's birthday.
$bdate = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
this is today's date:
$cdate = date("Y-m-d");
this is the validation part:
if($bdate > $cdate)
{
die('{status:0,txt:"Please check your birthday"}');
}
When the birthday's year and today's year are not the same like (different than 2011) it works.
However when the birthday's year and today's year are the same (both 2011) the validation part can't compare these to dates.
Example,
if $bdate is 2011-01-01
and $cdate is 2011-05-31
if($bdate > $cdate)
{
die('{status:0,txt:"Please check your birthday"}');
}
returns true.
Help needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的评论,您是否确认 $_POST 中的日期的所有组成部分都是正确的长度? -- 例如,没有单位数的月份或日期。那可能会把事情搞砸。
As per my comment, have you confirmed that all components of the date from $_POST are the correct length? -- eg no single-digit months or days. That could mess it up.