• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2739
  • Last Modified:

Auto Update date Modified for DateTime field

The answer to this might just be that it can't be done but if I have a table with a datetime type field, that I want to automatically update whenever the record is updated.  Now if the type was timestamp this could be done as follows:

ALTER TABLE `mytable` CHANGE `modified_date`, 'modified_date' TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL

However I can't get this to work with a DATETIME field.  I have tried variations such as NOW in place of CURRENT_TIMESTAMP with no luck.

Presumably this can be done with triggers, but I'd like to be able to do it via the basic attributes.
0
Ape
Asked:
Ape
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
unfortunately, the "trick" with ON UPDATE CURRENT_TIMESTAMP is not "portable" to datetime data type with NOW() function.
you HAVE to stick with timestamp, or use triggers
0
 
ApeAuthor Commented:
Not the answer I wanted, but the correct answer all the same.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now