dongzhang8680 2015-05-21 20:10
浏览 48

PHP - 将用户输入的日期与php date()进行比较?

I am trying to design some functionality in Wordpress where a user can create an "event" with a date they enter, which is something in the format of "MM/DD/YYYY". I want events to be archived if the inputted date is after the current date, so I've been doing something like...

$date = get_post_meta( get_the_ID(), 'Date', true );
$todaysDate = date('n\/d\/Y');

if( $date < $todaysDate) {
    // do stuff
}

Obviously, this is not the right way I should be going about this, but I'm not really sure what the best way to handle these inputted dates would be. The way I currently have it set up actually somewhat works, but months of October(10), November(11) and December(12) throw a wrench into the comparison. What would be a better, correct way to go about this?

  • 写回答

2条回答 默认 最新

  • doumei1203 2015-05-21 20:26
    关注

    Use strtotime() to parse about any English textual datetime description into a Unix timestamp. then do the comparison.

    if (strtotime($date) < strtotime($todaysDate))
    {
        // Do more stuff
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入