-1

In MySQL I want the current date as my default and not the time.

CREATE TABLE Order_T
(OrderID NUMERIC(11) NOT NULL,
OrderDate DATE DEFAULT NOW(),
CustomerID NUMERIC(11),
CONSTRAINT Order_PK PRIMARY KEY (OrderID),
CONSTRAINT Order_FK FOREIGN KEY (CustomerID) REFERENCES Customer_T (CustomerID));

I dont know why this doesn't work for the date.

I want the default date to be current date without the time stamp.

PM 77-1
  • 12,933
  • 21
  • 68
  • 111
  • use a trigger, see this answer [http://stackoverflow.com/questions/6283821/how-to-set-default-value-of-mysql-datetime-not-timestamp-to-now-or-current](http://stackoverflow.com/questions/6283821/how-to-set-default-value-of-mysql-datetime-not-timestamp-to-now-or-current) – Judith Palacios Mar 06 '17 at 23:48
  • 1
    MySQL?? Are you sure!?? – Strawberry Mar 06 '17 at 23:51
  • Possible duplicate of [How do you set a default value for a MySQL Datetime column?](http://stackoverflow.com/questions/168736/how-do-you-set-a-default-value-for-a-mysql-datetime-column) – Iłya Bursov Mar 07 '17 at 00:09

1 Answers1

0

use a trigger

DELIMITER ||

CREATE TRIGGER curr_date BEFORE INSERT ON Order_T FOR EACH ROW
BEGIN
  SET new.date = NOW();
END ||

DELIMITER ;

see this answer How to set default value of MySQL DateTime ( not TIMESTAMP ) to NOW() or Current_DateTIme?‌​t-value-of-mysql-dat‌​etime-not-timestamp-‌​to-now-or-current

Community
  • 1
  • 1
Judith Palacios
  • 413
  • 2
  • 9
  • I am quite new to the mysql and I am not quite sure where the trigger will come. Will it be inside the table or after creating the table? – Pratik Mandavgade Mar 07 '17 at 01:22
  • You need to create first the trigger because if you see the syntax you need asign the trigger to table, first create the table without default in date then create trigger – Judith Palacios Mar 07 '17 at 14:25