I am using laravel 5. I have try to use the
$now = DateTime(); $timestamp = $now->getTimestamp();
But it shows error likes this.
FatalErrorException in ProjectsController.php line 70: Call to undefined function App\Http\Controllers\DateTime()
What Can I do?
You can use Carbon\Carbon::parse($date); and then pass the Carbon object to eloquent model. I have date like '02 jul 2019' in My data input.
The Carbon package can be used for many purposes, such as reading the current date and time, changing the default date and time format, finding the difference between two dates, converting the date and time from one timezone to another timezone, etc.
DateTime
is not a function, but the class.
When you just reference a class like new DateTime()
PHP searches for the class in your current namespace. However the DateTime
class obviously doesn't exists in your controllers namespace but rather in root namespace.
You can either reference it in the root namespace by prepending a backslash:
$now = new \DateTime();
Or add an import statement at the top:
use DateTime; $now = new DateTime();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With