Home > Backend Development > PHP Problem > How to determine whether it is the time period of the day in php

How to determine whether it is the time period of the day in php

藏色散人
Release: 2023-03-14 13:34:01
Original
2839 people have browsed it

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.

How to determine whether it is the time period of the day in php

#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 &#39;<meta charset="utf-8" />&#39;; 
 
// 拟设一个日期 
 
$a = &#39;2012-06-28 10:10:10&#39;; 
 
// 截取日期部分,摒弃时分秒 
 
$b = substr($a,0,10); 
 
// 获取今天的日期,格式为 YYYY-MM-DD 
 
$c = date(&#39;Y-m-d&#39;); 
 
// 使用IF当作字符串判断是否相等 
 
if($b==$c){ 
 
    echo &#39;是今天&#39;; 
 
}else{ 
 
    echo &#39;不是今天&#39;; 
 
} 
 
?>
Copy after login

The second type:

<?php 
 
/** 
 
 * PHP判断一个日期是不是今天 
 
 * 琼台博客 
 
 */ 
 
echo &#39;<meta charset="utf-8" />&#39;; 
 
// 拟设一个日期 
 
$a = &#39;2012-06-28 10:10:10&#39;; 
 
// 转换为时间戳 
 
$a_ux = strtotime($a); 
 
// 转换为 YYYY-MM-DD 格式 
 
$a_date = date(&#39;Y-m-d&#39;,$a_ux); 
 
// 获取今天的 YYYY-MM-DD 格式 
 
$b_date = date(&#39;Y-m-d&#39;); 
 
// 使用IF当作字符串判断是否相等 
 
if($a_date==$b_date){ 
 
    echo &#39;是今天&#39;; 
 
}else{ 
 
    echo &#39;不是今天&#39;; 
 
} 
 
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template