Laravel Get created_at in Millisecond Timestamp
If you are fine with using DB::raw
you could try something like DB::raw("CONCAT(UNIX_TIMESTAMP(DATE(created_at)), '000000') as date")
.
@Neel as you're using Laravel, you already have a great tool called Carbon for working with PHP DateTime Class. There is no need to use UNIX_TIMESTAMP
for your purpose and this is not a good idea.
As you can find in Laravel documentation that created_at
and updated_at
are by default Carbon instances. So you can get timestamp like this and also much more
User::findOrFail($id)->created_at->timestamp
If you get
"created_at" => "2015-10-07 06:10:49"
The result will produce a timestamp using the query above like this 1444198249
After that you can manipulate your result as you wish.