UK Human Readable to Epoch Timestamp UserPageVisits:214 active 80 80 DaniWeb 561 60 2013-09-25T21:18:42+00:00

UK Human Readable to Epoch Timestamp


Hi all,

First tutorial submission.

The standardised strtotime() function really grinds my gears. I hate messing about with dates in different formats... so I mullered this little function up. It works perfectly - probably easier ways to do it, I don't know... I just include this function in my functions files and whenever I want to change a UK based human readable date to a timestamp... I run it through this; quick and simple! Hope you find it useful!

About the Author
code snippet
function UKtoEpoch($date){
	$date = explode("/",$date);
	$date = $date[1] . "/" . $date[0] . "/" . $date[2];
	$date = strtotime($date);
	return $date;

$humandate = "31/12/2013"; //31st December 2013
echo UKtoEpoch($humandate);
Member Avatar

Have you looked at the DateTime class? That will take all manner of inputs and give you whatever you want. It's especially useful as it can add and substract time too. For example:

$date = DateTime::createFromFormat('j/m/Y', $date); //e.g. '21/10/2009'
echo $date->format('Y-m-d'); //output 2009-10-21
echo $date->format('U'); // output unix time

Or with your example, just change the '/' to '-':

$cDate = str_replace('/','-',$date);
$time = strtotime($cDate);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.