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

Link to post
Share on other sites

Is it just me that needs clarification, what's a serial date? Have you got an example / format?

 

A serial date is a date with a general formatting in Excel

08/05/2009 = 39941

Link to post
Share on other sites

Try this

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

print convertSerialDate(733535);
?>

 

I was wondering

Is it possible to convert from dd/mm/yyyy format back to a serial date?

Link to post
Share on other sites

Of course, just requires the correct formula.

 

Thanks

 

How would that formula go?

Ive tried creating one based on the original formula you provided, but I was unsuccesfull

 

(sorry if im being cheeky)

Link to post
Share on other sites

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 :)

Link to post
Share on other sites

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

Link to post
Share on other sites

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.