Amazon thinks "12/2015" is a good way to return a date field. How to save to DB now?
Good evening,
my beloved Amazon (I really like them!! :-)) provide monthly reports. And for each month, the provide a date if you list - say - the last 12 months. And they seriously provide the month in "mm/yyyy" format, e.g. "12/2015".
Obviously, I dont want to store this as a string in the DB but as a date field.
Now I was thinking about the best ways how to tackle this.
1)The obvious solution: A model mutator. Well, long story short - I am insertin the data via
because I am talking potentially thousands of rows and also I am using composite keys which Laravel unfortunately does not support...
2)Store as string (arg) and use a mutator when RETRIEVING the model. Not nice but that could work
3)Manipulate the value before it is inserted into the DB. I dont like this one because I have several reports which I am processing with a handful of fully report-agnostic methods and I wouldnt like to start changing this.
4)...any other options? Like changing the date format of MySQL? :-)
It seems like you're looking at complicated solutions to a very simple problem : why don't you just format the date as you need in your PHP script, and store it as a proper DATETIME or DATE in the database?
Assuming that it's always MM/YYYY, you can juste split it up to get the individual components, and order/format them any way you want.
You can also use the Carbon library which is already used in Laravel.