'laravel database error when I try to convert an string to datetime

I'm on Laravel project that I didn't start, my problem is when I try to do an insert on laravel.

I need to insert a datetime, on Y-m-d h:i:s.v format but when i do the call

"date" => DB::raw('convert(datetime,GETDATE(),21)')

Insert returns

13-05-2022 15:14:29

That's not the format I need and don't know if the error come from laravel because when I do the same statement on DB it runs.

select convert(datetime,GETDATE(),21)

returns 2022-05-13 17:13:41.267

Thanks for your time.



Solution 1:[1]

I fixed the problem changing datatype on DB, changing datetime type to date.

Is not the first time that I had problems with datetime type so I suggest that don't use it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Lewis