Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mehrdad70's avatar

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value

I want to send the time in Persian and save it as a datetime in the database but i get an error

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1399-05-09 00:00:00' for column 'start_at' at row 1 (SQL: insert into `coupons` (`title`, `code`, `amount`, `quantity`, `is_general`, `type`, `description`, `start_at`, `expired_at`, `updated_at`, `created_at`) values (test1, 99808, 4, 1, 0, 0, ?, 1399-05-09 00:00:00, 1399-06-09 00:00:00, 2020-11-25 13:51:26, 2020-11-25 13:51:26))
    public function store(Request $request)
    {
        $coupon = Coupon::create([
            'title' => $request->title,
            'code' => $request->code,
            'amount' => $request->amount,
            'quantity' => $request->quantity,
            'is_general' => $request->is_general,
            'type' => $request->type,
            'description' => $request->description,
            'start_at' => date('Y-m-d H:i:s' , strtotime($request->start_at)),
            'expired_at' => date('Y-m-d H:i:s' , strtotime($request->expired_at)),
        ]);

        $coupon->categories()->sync($request->category_id);
        $coupon->users()->sync($request->user_id);
        $coupon->courses()->sync($request->course_id);

        return redirect(route('coupons.index'));

    }
0 likes
10 replies
siangboon's avatar

Is the column type for start_at a datetime or timestamp?

siangboon's avatar

every schema data type have it limit, in integer, string, date, datetime, timestamp and etc also... there are minimum and maximum value, in mysql, datetime* min and max values are '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999', but timestamp range '1970-01-01 00:00:01.000000' to '2038-01-19 03:14:07.999999'.

1399-05-09 00:00:00 is less than 1970-01-01 00:00:01.000000 hence it gave you incorrect datetime value error message. For your information, timestamp value also in datetime format but does not mean it is same, datetime type and timestamp is bit different at least the min and max value is difference,

2 likes
mehrdad70's avatar

It is not true?

            $table->timestamp('start_at');
            $table->timestamp('expired_at');
MichalOravec's avatar

timestamp is limited to have values between 1970-01-01 00:00:01.000000 and 2038-01-19 03:14:07.999999

mehrdad70's avatar

Is it a function to store Persian date as dateTime when stored in the database?

powersupersport's avatar

Most likely you cannot do that if the field gets saved as a timestamp. Timestamps are 32-bit integers and this particular date is far beyond this limit.

mary_anne's avatar

@mehrdad70 I know it's late already.

But, you can set your column datatype as date then parse the request using carbon facade like this Carbon::parse($request->start_at)

Please or to participate in this conversation.