How to get DateTime in php AGI

Hi all,
I like to create the application with AGI Programing.
In the PHP file I need to get the current DateTime of server. for get that in php I use this syntax ($date = new DateTime()) But when I use this my AGI program can’t run correctly.

In the external PHP file when I use that syntax easily I can get the system correct Date and Time…!!!

I have a question, we can’t use PHP syntax in the AGI programing whit PHP language?

This location of my file in var/lib/asterisk/agi-bin/Sample.php

Guys please advice me.
Many thanks.

Note, if this had been an Asterisk issue, you should have used Asterisk Support.

david, thanks for your replay
Yes, this issue has been asterisk.
When I use this syntax ($date = date(‘Y-m-d’)) is work correctly. But when I use this syntax ($date = new DateTime()) is not work.
So I need to create a datetime variable in phpAGI.

No. The issue is either with PHPAGI, or with PHP.

I think right, But I don’t know why some PHP syntax is easily work in phpagi and some codes not work…!!!