Convert number to date

2

Good afternoon,

I would like to know if there is a way to convert date into PHP.

  

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

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

    
asked by anonymous 26.05.2017 / 20:23

2 answers

1

Dates in Excel are stored in days as of January 1, 1900, so for dates after that period you can create a DateTime object and format the date to display, eg:

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

Ideone Example

Check out this answer in SOE

    
26.05.2017 / 20:43
0
string date ( string $format [, int $timestamp ] )
  

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

See more about date.
More information this answer.

    
26.05.2017 / 20:32