Home  >  Article  >  Backend Development  >  How to convert birthday to timestamp in php

How to convert birthday to timestamp in php

藏色散人
藏色散人Original
2022-12-14 09:58:545426browse

How to convert birthday to timestamp in php: 1. Create a PHP sample file; 2. Check whether the birth date to be converted is around 1970; 3. Convert the birth date to a timestamp through the strtotime function. .

How to convert birthday to timestamp in php

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

How to convert birthday to timestamp in php?

php Convert date of birth into timestamp

1. Sometimes we need to convert date of birth into timestamp

But people born before 1970 , when the date of birth is converted into a timestamp, the timestamp is a negative number; for people born after 1970, when the date of birth is converted into a timestamp, the timestamp is a positive number

Such as:

echo strtotime("1960-01-01");//结果:-315648000
echo strtotime("1984-01-01");//结果:441734400

However, it does not affect the display result of converting timestamp into date:

Such as:

echo date("Y-m-d",-315648000);//结果:1960-01-01
echo date("Y-m-d",441734400);//结果:1984-01-01

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to convert birthday to 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