Jump to content

Convert serial date into 'dd/mm/yyyy'


Mike SD

Recommended Posts

Try this

<?
function convertSerialDate($date)	{
	$timestamp = ($date - 25569) * 86400;
	return date("d/m/Y",$timestamp);
}

print convertSerialDate(733535);
?>

 

Fantastic

 

I have been searching the internet all morning for an answer to this one

Thank you very much

Reversing neil.johnson's function, you get:

 

<?php
function date2serial($date) {
//convert dd/mm/yyyy format to yyyy-mm-dd format
$date_arr = explode('/', $date);
$std_date = implode(array_reverse($date_arr), '-');
$timestamp = strtotime($std_date);
return round(($timestamp + 25569 * 86400) / 86400);
}
?>

 

Edit: But I'm not sure if round() gives us the desired serial for every date.

Edit 2: And some quick calculation leaves us with the simpler

 

return round(($timestamp / 86400) + 25569);

 

instead of the current return line :)

Reversing neil.johnson's function, you get:

 

<?php
function date2serial($date) {
//convert dd/mm/yyyy format to yyyy-mm-dd format
$date_arr = explode('/', $date);
$std_date = implode(array_reverse($date_arr), '-');
$timestamp = strtotime($std_date);
return round(($timestamp + 25569 * 86400) / 86400);
}
?>

 

Edit: But I'm not sure if round() gives us the desired serial for every date.

 

Thank you so much

 

This has made me very very happy

I have run a test and it converted the data back to a serial date successfully

 

I will add it to my script and let you know if I encounter any problems

 

Thank you

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.