-2

I want to fetch only date and time from this object:

$current=new DateTime

Will display:

DateTime Object ( [date] => 2014-06-06 17:35:08 [timezone_type] => 3 [timezone] => Asia/Singapore )

I want to fetch only date. How can I do that? I tried $current->date but got an error message:

UUndefined property: DateTime::$date
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Friend
  • 1,326
  • 11
  • 38
  • 62
  • possible duplicate of [Why can't I access DateTime->date in PHP's DateTime class? Is it a bug?](http://stackoverflow.com/questions/14084222/why-cant-i-access-datetime-date-in-phps-datetime-class-is-it-a-bug) – raina77ow Jun 06 '14 at 09:43

2 Answers2

0

If you want the current date you need to do something like this:

$dt = new DateTime();
$date = $dt->format('Y-m-d H:i:s');

See more information at documentation.

Antoine Augusti
  • 1,598
  • 11
  • 13
0

To fetch Current date and time in PHP you can to try this...

date_default_timezone_set("America/Los_Angeles");
echo "Current Date is" . date("d-m-Y") . "<br>";
echo "Current Time is " . date("h:i:sa");
bish
  • 3,381
  • 9
  • 48
  • 69
vasanth
  • 715
  • 8
  • 18