Search code examples
phplaraveltimestamplaravel-5.8php-carbon

The separation symbol could not be found Data missing


I'm working with Laravel 5.8 and I wanted to show a popup message if the UNIX timestamp of the current date is equal to the defined Unix timestamp of the popup.

So in order to do that, I added this at the Controller:

$date1= $popup->datep; // returns 1636403400

$date1 = Carbon::createFromFormat('Y-m-d H:i:s', $date1);

dd($date1);

But instead of getting the result of $date1, I get this error:

The separation symbol could not be found Data missing

So what's going wrong here? How can I solve this issue?


Solution

  • You are specifying a format that is clearly not an unix timestamp. Use method for the timestamp.

    $date = Carbon::createFromTimestamp($popup->datep);
    

    If you want to compare it to be the same date, you should do the following. I don't assume you want to compare it by the hour or second, that those will almost never match.

    $date->startOfDay()->eq(now()->startOfDay());