CURDATE() syntax helps please

Hi all

I am trying to create a column within my pre existing table ‘property’ i want this column to represent the date the ‘job’ was ordered; so i am trying to utilise CURDATE(), although i am having major problems with the syntax and i cant see where I am going wrong. I know it will be simple, but please help.

alter table property add column date_job_rec datetime not null curdate();

my MySQl version is 5.1.47

Many thanks in advance

You can’t use a function as a default value, and I don’t know of a way to achieve what you want using a DATETIME field. You can however do it using a TIMESTAMP field, see here http://dev.mysql.com/doc/refman/5.0/en/timestamp.html

:slight_smile:

never completely trust anything you don’t find on the mysql.com site – in this instance, w3schools is wrong

I was lifting the idea direct from w3.schools.org - http://www.w3schools.com/sql/func_curdate.asp.

where they have the line:

OrderDate datetime NOT NULL DEFAULT CURDATE()

i havent tried any other options tbh.

Have you tried using NOW() with a date/time field?