<?php
$firstdate = '2011-11-16';
$sample = date("d-m-Y", strtotime($firstdate));
echo $sample;
?>
I have a column in a table with date in this format 2011-11-16
But I need it in reverse, so I’ve used the following code.
The problem is that when the date is 0000-00-00, it prints 01-01-1970.
Is there a way of making it print 00-00-0000 instead? Please note that I’m looking to reverse it to British format. 00-00-0000.
Thanks
The problem is in the way dates are represented internally. They use what’s called Unix time, in which the date is represented as a number of seconds after the “Unix epoch”, which is 1/1/1970. This is why the
datefunction (correctly) represents 0 (which is whatstrtotimereturns when you pass it0000-00-00) as Jan 1, 1970.The only solution I can think of is something like this: