Home > Article > Backend Development > How to determine whether it is the time period of the day in php
php method to determine whether it is the time period of the day: 1. Set a date; 2. Intercept the date part and discard the hours, minutes and seconds; 3. Get today's date; 4. Use IF as a string to determine whether It’s not just a time period of the day.
#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
How does php determine whether it is the time period of the day?
PHP determines whether the time is the time of the day
The first type:
<?php /** * PHP判断一个日期是不是今天 * 琼台博客 */ echo '<meta charset="utf-8" />'; // 拟设一个日期 $a = '2012-06-28 10:10:10'; // 截取日期部分,摒弃时分秒 $b = substr($a,0,10); // 获取今天的日期,格式为 YYYY-MM-DD $c = date('Y-m-d'); // 使用IF当作字符串判断是否相等 if($b==$c){ echo '是今天'; }else{ echo '不是今天'; } ?>
The second type:
<?php /** * PHP判断一个日期是不是今天 * 琼台博客 */ echo '<meta charset="utf-8" />'; // 拟设一个日期 $a = '2012-06-28 10:10:10'; // 转换为时间戳 $a_ux = strtotime($a); // 转换为 YYYY-MM-DD 格式 $a_date = date('Y-m-d',$a_ux); // 获取今天的 YYYY-MM-DD 格式 $b_date = date('Y-m-d'); // 使用IF当作字符串判断是否相等 if($a_date==$b_date){ echo '是今天'; }else{ echo '不是今天'; } ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine whether it is the time period of the day in php. For more information, please follow other related articles on the PHP Chinese website!