Govind Singh
Govind Singh

Reputation: 15490

Inserting an older date in mysql table

tried this query for entry a two day older date

INSERT INTO `subject` (`id` ,`marks` ,`entry`)
VALUES ('12121', '12','CURRENT_DATE()-2');

it gives

    id  |  marks  |  entry
  12121     12      0000-00-00

also tried 'CURRENT_DATE() interval 2'

Upvotes: 0

Views: 574

Answers (2)

Rahul Tripathi
Rahul Tripathi

Reputation: 172428

Try this:

INSERT INTO `subject`(`id` ,`marks` ,`entry`)
 SELECT '12121', '12', CURRENT_DATE() - interval 2 day;

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1269753

You are inserting a string into a date column. The string gets converted to a number with a value of 0. Instead, try this:

INSERT INTO subject(id, marks, entry)
    SELECT '12121', '12', CURRENT_DATE() - interval 2 day;

Upvotes: 2

Related Questions