Home > Software design >  The separation symbol could not be found Data missing
The separation symbol could not be found Data missing

Time:11-09

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?

CodePudding user response:

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());

CodePudding user response:

Regarding Carbon Docs:

createFromFormat() is mostly a wrapper for the base php function DateTime::createFromFormat.

which is means that your second parameter must be a valid date/time format, not a timestamp.

The DateTime::create docs:

$datetime
String representing the time.

Instead, you need to use the createFromTimestamp instantiator.

$date1 = Carbon::createFromTimestamp($date1);
  • Related