Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php determine the date of the year?

Shulou Source: shulou.com Published: 2022-06-02 09:47:10 09月19日 Update

This article introduces php how to judge the specified date is the first day of the year, the content is very detailed, interested friends can refer to, hope to help you.

Judgment method: 1, use the strtotime () function to convert the specified date into a timestamp format, syntax "strtotime (" specified date ")"; 2, use the date () function to calculate the day of the specified timestamp of the year, syntax "date (" z ", timestamp)".

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

In php, you can use the date () function to calculate the day of the year on which the specified date is.

The date () function can specify a timestamp to change to the day of the year.

Syntax:

Date (format,timestamp)

When the parameter format is set to z, the specified timestamp timestamp can be calculated as the day of the year. Note: days start from 0 (from 0 to 365).

Example: calculate the specified date 2018-01-18 is the day of the year

Output:

Parsing:

Because the date () function handles timestamps, you need to first use strtotime () to convert the specified date into a timestamp format

Then use date ("z", $time) to calculate the day of the year.

Because the number of days returned by date ("z", $time) starts at 0, you can add 1 to the return value.

About php how to judge the specified date is the first day of the year to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Date time function grammar content days more format help good interest parameter foundation guys buddies tutorials articles methods environment computer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology Shulou Tech Info MariaDB vpn