Convert number to date

Good afternoon,

I would like to know, if there is how to convert number to date in PHP.

Example, in Excel the number 42873 is equivalent to date 18-05-2017. And I can do the opposite, too.

Is there any function in PHP, to which I can do this conversion?

Author: Tony Anderson, 2017-05-26

2 answers

Dates in Excel are stored in numbers of days from January 1, 1900, so for dates after this period you can create an object DateTime and format the date for display, Example:

$n = 42873;
$dateTime = new DateTime("1899-12-30 + $n days");
echo $dateTime->format("d/m/Y");

Example Ideone

Check out this answer in SOE

 1
Author: abfurlan, 2017-05-26 18:43:19
string date ( string $format [, int $timestamp ] )

The optional timestamp parameter is a Unix integer timestamp whose default it is the local time if timestamp is not reported. In other words, the default is the value of the time () function.

See more about date.
More information in this answer.

 0
Author: Homer Simpson, 2017-05-26 18:32:28