I’m doing a mysql table and i have one column that has current timestamp on update. This is great because i can see exactly when someone uploads something. But i dont want the column to change when they edit their upload. Is it best to stick with one column named “date created” and have NO on update or go with two columns “date created & “date modified” – if so whats the best practice for column attributes, and PHP update statements?
Share
I usually like to have a separate “CreateDate” and “LastModifiedDate”.
As for setting it, it would be nice if you could just set the default value for the CreateDate column to
NOW(), but MySQL doesn’t allow that.So, the easiest option would be to use an insert trigger to do it:
ETA:
You can use a
TIMESTAMPfield with a default value ofCURRENT_TIMESTAMPand theON UPDATE CURRENT_TIMESTAMPconstraint for the LastModifiedDate as well. Unfortunately you can’t have two suchTIMESTAMPcolumns on the same table, so the trigger is necessary to handle the CreateDate column.