I am trying to display dates in the European format (dd/mm/yyyy)
with strtotime
but it always returns 01/01/1970.
Here is my codeline :
echo "<p><h6>".date('d/m/Y', strtotime($row['DMT_DATE_DOCUMENT']))."</h6></p>";
In my database, the field is a varchar and records are formated like yyyy.mm.dd
I use the same codeline for another field that is formated like yyyy-mm-dd (varchar too) and it works fine.
Thanks for your help.
PHP strtotime() function returns a timestamp value for the given date string. Incase of failure, this function returns the boolean value false.
Code for converting a string to dateTime $input = '06/10/2011 19:00:02' ; $date = strtotime ( $input ); echo date ( 'd/M/Y h:i:s' , $date );
For a very basic fix based on your code: $day='2010-01-23'; // add 7 days to the date above $NewDate = date('Y-m-d', strtotime($day .
You can use DateTime::modify to add time, but I would just do time()+10800 . Show activity on this post. $time = new DateTime("+ 3 hour"); $timestamp = $time->format('Y-M-d h:i:s a');
Since the format yyyy-mm-dd
works, try to replace .
with -
:
date('d/m/Y', strtotime(str_replace('.', '-', $row['DMT_DATE_DOCUMENT'])));
Try with:
$date = date_parse_from_format("Y.m.d", $row['DMT_DATE_DOCUMENT']);
$time = mktime($date['hour'], $date['minute'], $date['second'], $date['month'], $date['day'], $date['year']);
echo "<p><h6>".date('d/m/Y', $time)."</h6></p>";
(Using date_parse_from_format()
instead of strtotime()
)
Or just:
$date = date_parse_from_format("Y.m.d", $row['DMT_DATE_DOCUMENT']);
echo "<p><h6>{$date['day']}/{$date['month']}/{$date['year']}</h6></p>";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With