Home > Article > Backend Development > How to convert numerical value to date format in php
php method to convert values into date format: 1. Create a php sample file; 2. Get the seconds through the "$time = (40847 – 25569) * 24*60*60;" method; 3. . Use the "echo date('Y-m-d H:i:s', $time);" method to convert it into date format and output it.
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, Dell G3 computer.
php How to convert numerical values into date format?
php Convert excel numerical format to date format
In excel: 40847 corresponds to 2011-10-31, which is the numerical representation of date.
In PHP, echo date('Y-m-d H:i:s',40847);//The result is 1970-01-01 11:52:30
Reason:
PHP's time function is calculated from January 1, 1970, and the unit is seconds. However, EXCEL calculates the unit in days starting from 1900-1-1.
It would be easier to process if we only calculate the time after 1970.
First get the number represented by 1970-1-1 in EXCEL. I checked it is 25569.
Now we need to use the function to display 40947 in excel correctly in php
The code is as follows:
<?php $time = (40847 – 25569) * 24*60*60; //获得秒数 echo date('Y-m-d H:i:s', $time); //出来 2011-10-31 ?>
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of How to convert numerical value to date format in php. For more information, please follow other related articles on the PHP Chinese website!