我正在構建演示軟件的數據庫。數據庫中的日期字段必須是最新的,因爲它將不斷重建,因此日期始終是當前日期。但是DATE()
函數似乎沒有正常工作。用當前日期創建數據庫
舉個例子,我在命令行下進入一個數據庫導入MySQL的腳本,這是我要構建的end_date
場今天,這是獲得插入
-- Table structure for table `tasks`
--
CREATE TABLE `tasks` (
`id` int(11) unsigned NOT NULL,
`funeral_id` int(11) DEFAULT NULL,
`deceased_id` int(11) DEFAULT NULL,
`contact_id` int(11) DEFAULT NULL,
`task_type_id` int(3) DEFAULT NULL,
`assigned_id` varchar(30) DEFAULT NULL,
`start_date` datetime DEFAULT NULL,
`end_date` datetime DEFAULT NULL,
`notes` text,
`courtesy_call` tinyint(1) DEFAULT NULL,
`q_accepted` tinyint(1) DEFAULT NULL,
`q_mailed` tinyint(1) DEFAULT NULL,
`q_returned` tinyint(1) DEFAULT NULL,
`status_id` int(1) DEFAULT '0',
`user_created_id` int(3) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`user_modified_id` int(3) DEFAULT NULL,
`modified` datetime DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tasks`
--
INSERT INTO `tasks` (`id`, `funeral_id`, `deceased_id`, `contact_id`, `task_type_id`, `assigned_id`, `start_date`, `end_date`, `notes`, `courtesy_call`, `q_accepted`, `q_mailed`, `q_returned`, `status_id`, `user_created_id`, `created`, `user_modified_id`, `modified`) VALUES
(1, 1, 1, 1, 1, '39', NULL, 'DATE_ADD(NOW(), INTERVAL 4 DAY)', NULL, 0, NULL, NULL, NULL, 0, 1, '2016-05-27 16:40:17', NULL, '2016-05-27 16:40:17');
表的一加四天,功能DATE_ADD(NOW(), INTERVAL 4 DAY)
返回0000-00-00 00:00:00
而且,無論我試着使用NOW()
或CURRENT_TIMESTAMP()
返回相同的數值0000-00-00 00:00:00
這是爲什麼?
它給出了同樣的結果 –
@NishuTayal:你的回答並沒有糾正錯誤。看看[PerroVerd的答案](http://stackoverflow.com/a/37746655/767881)。 –
@RavinderReddy:哦,是的..錯字留在查詢中。糾正它 –