0

I'm in a huge confusion. Trying with bunch of combinations using DATE(), CURDATE(), NOW(), STR_TO_DATE(), CONVERT() and other functions, I can't set up a default value for my DATE type column which is going to store current date in 'yyyy-MM-dd' format. What syntax should it be for this? I have even try generated columns but no effects at all. Typing into console short examples like 'SELECT DATE(CURDATE())' works fine but when I want to set it up as a default value of given column it gives me an error. Such a tiny thing to do and such a problem... I'm using 5.7.24 version of MySQL Server.

ALTER TABLE my_table ADD COLUMN today DATE DEFAULT ..................
Mazhar
  • 3,797
  • 1
  • 12
  • 29
Limak
  • 47
  • 1
  • 8
  • Dates have no format – HoneyBadger Nov 12 '19 at 08:25
  • [This](https://stackoverflow.com/questions/168736/how-do-you-set-a-default-value-for-a-mysql-datetime-column) question has some answers that might help you. – Moloy Adhikary Nov 12 '19 at 08:27
  • Does this answer your question? [How do you set a default value for a MySQL Datetime column?](https://stackoverflow.com/questions/168736/how-do-you-set-a-default-value-for-a-mysql-datetime-column) – Amit Baranes Nov 12 '19 at 08:43
  • Indeed, I fixed it out using triggers for now but my question is still valid. Is there a possibility to do it just a casual way using keyword DEFAULT? Triggers have their own pros and cons and the code gets a bit messed up. – Limak Nov 12 '19 at 09:35
  • Are you sure you even want to use a `Date` column instead of a `Timestamp` column? See [What difference between the DATE, TIME, DATETIME, and TIMESTAMP Types](https://stackoverflow.com/questions/31761047/what-difference-between-the-date-time-datetime-and-timestamp-types/56138746#56138746). – Booboo Nov 12 '19 at 13:03
  • Nice one. It explained a lot. Thanks. – Limak Nov 30 '19 at 10:37

0 Answers0