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?
I didn't mean to copy the same answer, that is why I didn't accept my own answer.
Actually when I add use DateTime
in top of the controller solves this problem.
If you just want to get the current UNIX timestamp I'd just use time()
$timestamp = time();
Best way is to use the Carbon dependency.
With Carbon\Carbon::now();
you get the current Datetime.
With Carbon you can do like enything with the DateTime. Event things like this:
$tomorrow = Carbon::now()->addDay();
$lastWeek = Carbon::now()->subWeek();
Source: Stackoverflow.com