You should store in the correct format, you can display in whatever format you want. I advise not use varchar for that.
Laravel printing the wrong date
I want my blog post created and updated dates to look like: December 2, 2023... the F j, Y format.
So in my blog model I have added the protected $dateFormat = 'F j, Y'; attribute and it works. I've also edited the timestamp field and made it varchar(255) instead of the usual timestamp because mysql couldn't handle the date format.
This seems to work, when I look into the database, I see that the created at field is created properly but when I go to post it in my views, it posts as 2023-12-02 02:49:02 . The only way I can fix this issue that I've found so far is if I set public $timestamps = false; in the Blog model, but that means that I would have to manually set the values to those fields. While this is not a problem, I was wondering if there was a better way to accomplish this?
do not use string for dates because you can then never sort or filter by date
Your need to show "December 2 2023" is purely presentational and should be treated when outputting the blade only.
By default Laravel will convert created_at to an instance of Carbon datetime object, so in blade
{{ $post->created_at->format('F j, Y') }}
Just convert when displaying, not when storing
Please or to participate in this conversation.