Skip to content
Advertisement

Changing date format – Laravel

I have a column in my table named expiry which has type VARCHAR. In the column, there is a mixture of date format like YYYY-MM-DD and MM-DD-YYYY.

How can i re-arrange the format MM-DD-YYYY to YYYY-MM-DD in my laravel view blade ?

View

JavaScript

In the view above, it throws an error

Could not parse ’02-27-2021′: DateTime::__construct(): Failed to parse time string (02-27-2021) at position 0

How can i solve this ?

Product Output

JavaScript

Advertisement

Answer

I’m actually going to just suggest that you stop storing date information in a text varchar column. Instead, you should be using a proper MySQL date column. Here is how you can rectify the situation from MySQL:

JavaScript

I wouldn’t even bother trying to manage this column from Laravel. Even if someone gives you an answer, it will be ugly and a lot of work, and also not best practice.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement