-1

I don't know PHP nor do I know how to edit it. I don't know what version of PHP my client's site is using or if I need to edit other php files. I've tried examples listed in other posts, but I'm obviously doing something wrong.

Can someone help me write the code below so that the outputted format is 09/13/2015

Here is my code:

  <?php 
   $date = get_field('date');

   $Y = substr($date, 0, 4);
   $m = substr($date, 4, 2);
   $d = substr($date, 6, 2);

   $time = strtotime("{$Y}-{$m}-{$d}");
   ?>

<?php echo $Y; ?><?php echo $m; ?><?php echo $d; ?>

When I try editing it ends up giving me the Jan 1, 1970 date. So frustrated!

Thank you -

1 Answers1

0

Try this

$date = "09132015";
$convertedDate = date("Y-m-d", strtotime($date));
chandresh_cool
  • 11,753
  • 3
  • 30
  • 45
  • "*The date that is getting pulled is one of an old recording, so it isn't today's date, but a historical one.* (...) *When I try, it ends up giving me the Jan 1, 1970 date*" – al'ein Oct 08 '15 at 13:38
  • Thank you! However I'm SO dumb when it comes to PHP, I'm literally 'just' starting to learn it, yesterday was my first time dabbling. Are you able to show me how my code would look with your edits? – user3884406 Oct 08 '15 at 15:46