首页 > 解决方案 > 如何将这个日期和时间 8 月 15 日下午 8:00 IST (GMT + 5:30) 与 PHP 中的当前日期和时间进行比较

问题描述

如何比较这个日期和时间

15 AUGUST at 8:00 PM IST ( GMT + 5:30)

到 PHP 中的当前日期和时间, 15 AUGUST at 8:00 PM IST ( GMT + 5:30)此日期存储在 db 中,需要与当前时间进行比较,如果当前时间少 15 分钟,则需要触发我的逻辑。

标签: phpmysqlwordpress

解决方案


            $dateTime    = new DateTime('now', new DateTimeZone('Asia/Kolkata')); 
            $classDate   = explode(' ', '27 AUGUST at 8:00 PM IST ( GMT + 5:30)');
            $currentDate = explode(' ',date("d F")." at ".$dateTime->format("h:i A").' '.'IST ( GMT + 5:30)');
            
            if ($currentDate['0'] == $classDate['0']) {
                if ($currentDate['1'] == $classDate['1']) {
                    if ($currentDate['4'] == $classDate['4']) {
                        $minutes = (strtotime($classDate['3']) - strtotime($currentDate['3']))/60;
                        if ($minutes <= 15 && $minutes >= 0) {
                            echo "Your class is ready, Join now";
                        }
                    }
                }
            }
Here i have exploded the dates and compared the date month as well compared time 
converting to `strtotime()` and boom.......

推荐阅读