0

PHP:

<p><img src="<?php echo base_url()?>assets/images/calendar.png" alt=""><?php echo date('d m Y', str_replace('/', '-', $pet['pet_lost_date']))?> by <?php echo $pet['reg_first_name'].' '.substr($pet['reg_last_name'], 0, 1);?>.<b></b> </p>

Error:

A non well formed numeric value encountered

It displaying Error. How can I resolve this Error please help me.

Shah Rushabh
  • 147
  • 4
  • 16

1 Answers1

1

date() takes an integer timestamp as the second argument, not a string. Try strtotime():

echo date('d m Y', strtotime(str_replace('/', '-', $pet['pet_lost_date'])));

But if your date string is in the proper format, don't replace:

echo date('d m Y', strtotime($pet['pet_lost_date']));

But be careful as strtotime() treats dates with a / as U.S. style dates m/d/Y and dates with - are treated as d-m-Y, or maybe that's what you are trying to correct?

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
  • Although correct, I believe this answer can be improved by suggesting to omit the use of str_replace as it is redundant because the 'strtotime()' function can handle a date delimited by `/`. – coderodour Apr 17 '17 at 19:45
  • That is addressed as `strtotime` handles them differently, hence the _or maybe that's what you are trying to correct?_. But I clarified. – AbraCadaver Apr 17 '17 at 19:57