Home  >  Article  >  Backend Development  >  How to determine whether it is today given a specified timestamp in PHP

How to determine whether it is today given a specified timestamp in PHP

青灯夜游
青灯夜游Original
2021-12-01 14:55:202920browse

In PHP, you can use the date() function and the "==" operator to determine whether the specified timestamp is today. The syntax "if(date('Ymd', specified timestamp)==date( 'Ymd')){echo 'It's today';}else{echo 'Not today';}".

How to determine whether it is today given a specified timestamp in PHP

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php determines the specified time Is the method of stamping today

Implementation idea:

  • Use date() to format today's date and convert it to "year and month" Day" format

  • Use date() to format the specified timestamp and convert it to "Year Month Day" format

  • Use "= The =” operator determines whether they are equal. If they are equal, the specified timestamp is today

Implementation code:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);
$timestamp = time();  // 获取一个时间戳
if(date(&#39;Ymd&#39;, $timestamp) == date(&#39;Ymd&#39;)) {
    echo &#39;是今天&#39;;  
}else{
	echo &#39;不是今天&#39;;  
}
?>

How to determine whether it is today given a specified timestamp in PHP

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine whether it is today given a specified timestamp in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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