search
Home类库下载PHP类库How to get the starting timestamp and ending timestamp of today, yesterday, last week, and this month in php

php’s method of obtaining the start timestamp and end timestamp of today, yesterday, last week, and this month mainly uses PHP’s time function mktime. Let's go straight to the topic first and use mktime to illustrate how to use mktime to get the start timestamp and end timestamp of today, yesterday, last week, and this month. Then we will introduce the function and usage of mktime function.

//php gets today’s start timestamp and end timestamp

$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y' ));

$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;

// PHP gets yesterday's start timestamp and end timestamp

$beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));

$endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;

//php gets the data from last week Start timestamp and end timestamp

$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date(' Y'));

$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y' ));

//php gets the start timestamp and end timestamp of this month

$beginThismonth=mktime(0,0,0,date('m'),1,date('Y' ));

$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));

PHP mktime() function is used to return The Unix timestamp of a date.

Syntax

mktime(hour, minute, second, month, day, year, is_dst)

Parameter Description

hour Optional. Specified hours.

minute optional. Specified minutes.

second optional. Specifies seconds.

month optional. Specifies the numeric month.

day optional. Specify days.

year optional. Specified year. On some systems, legal values ​​are between 1901 - 2038. However, this limitation no longer exists in PHP 5.

is_dst

Optional. Set to 1 if the time is during Daylight Saving Time (DST), 0 otherwise, or -1 if unknown.

Since 5.1.0, the is_dst parameter is deprecated. Therefore the new time zone handling features should be used.

Usage

The parameter always represents a GMT date, so is_dst has no effect on the result.

The parameters can be left empty from right to left, and the empty parameters will be set to the corresponding current GMT value.

Note that before PHP 5.1, if the parameters of this function are illegal, false will be returned.

Also note that this function is very useful for date operations and verification. It can automatically correct out-of-bounds input, such as:

echo(date("M-d-Y",mktime(0,0,0,12,36,2001)));


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment