Carbon (laravel) deal with invalid date

前端 未结 4 1948
面向向阳花
面向向阳花 2021-02-20 05:22

I have a quite simple problem.. I use the Carbon::parse($date) function with $date = \'15.15.2015\'. Of course it can not return a valid string because

4条回答
  •  清酒与你
    2021-02-20 06:09

    Try this

    $birth_date = Carbon::createFromFormat('dmy', $birth_date_mark)->startOfDay();
    if ($birth_date->format('dmy') !== $birth_date_mark) {
         throw new OperationException(trans('exception.invalid_birth_date'));
    }
    

提交回复
热议问题