1

PHP:

<?php echo date("d-m-Y",strtotime($pet['pet_lost_date']));?>

Variable Value:-

[pet_lost_date] => 16/04/2017

Output:

01-01-1970

Please help me why I searched a lot but I found nothing helpful.

Why is it appearing the wrong date? Where is an Error?

And How can I count from given date to toady total days month and years?

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Shah Rushabh
  • 147
  • 4
  • 16

2 Answers2

0

You need to format the date a bit differently:

$pet['pet_lost_date'] = "16/04/2017";
$pet['pet_lost_date'] = str_replace('/', '-', $pet['pet_lost_date']);
echo date("d-m-Y",strtotime($pet['pet_lost_date']));

Output:

16-04-2017
Marcin
  • 1,488
  • 1
  • 13
  • 27
0

Php date() doesn't recognise dd/mm/yy format

Do like below:-

<?php 
if(!empty($pet['pet_lost_date'])){
  echo date("d-m-Y",strtotime(str_replace('/','-',$pet['pet_lost_date'])));
}
?>

Output:- https://eval.in/777593

Using date_diff():-

https://eval.in/777610

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98