-3
<?php
         $date = new datetime;
        echo $date->format('m-d-y');
 ?>

Can someone see something I can't? I keep getting unexpected $date on the 2 line. (I'm very new when it comes to php. Any help appreciated.)

3 Answers3

0

When using the Datetime class you need to instantiate your object using $date = new DateTime(); and then to display the date use echo $date->format('Y-m-d'); to display the date on the page (Y-m-d just being a stand in for the date format got need).

Code

$date = new DateTime();
echo $date->format('Y-m-d');
SC7639
  • 94
  • 1
  • 10
-1

check the case of your = new datetime. I think it should be

 $date = new DateTime();

reference

DateTime Class

sasori
  • 5,249
  • 16
  • 86
  • 138
-1
<?php 
    $date = new DateTime();
    echo date_format($date,"m-d-y");
?>

Well you can use this. PHP date_format function.

LecheDeCrema
  • 392
  • 5
  • 21