如何在mysql查询中手动添加时间或日期?

时间:2022-10-13 12:02:52

I just want to ask, is there a way I can manually input a specific time or date in mysql database?

我只是想问,有没有办法在mysql数据库中手动输入特定的时间或日期?

I'm using addtime() and adddate() but the results are 0000

我正在使用addtime()和adddate(),但结果是0000

here is my table type:

这是我的表类型:

+----------------+------------+------+-----+---------+-------+
| Field          | Type       | Null | Key | Default | Extra |
+----------------+------------+------+-----+---------+-------+
| Number_of_days | varchar(3) | NO   | PRI | NULL    |       |
| Date_In        | date       | NO   |     | NULL    |       |
| Time_In        | time       | NO   |     | NULL    |       |
+----------------+------------+------+-----+---------+-------+

and this is my command

这是我的命令

INSERT INTO Date_And_Time_In (Number_of_days, Date_In, Time_In) VALUES ('02', 'DATE(2013-06-03)', 'TIME(12:10:00)' );

and here's the output

这是输出

mysql> select * from Date_And_Time_In;
+----------------+------------+----------+
| Number_of_days | Date_In    | Time_In  |
+----------------+------------+----------+
| 01             | 2013-06-03 | 11:32:24 |
| 02             | 0000-00-00 | 00:00:00 |
+----------------+------------+----------+

the first one was from the curdate() and curtime(). I'm just trying to experiment though what if I want to change a specific time or date what mysql command what I use?

第一个来自curdate()和curtime()。我只是想试验一下,如果我想改变一个特定的时间或日期,我用什么mysql命令?

3 个解决方案

#1


0  

When you add quotes around MySQL functions, they are not executed (because you have turned them into a string); and any invalid date value will result in 0000. Remove the quotes and it should work great.

当您在MySQL函数周围添加引号时,它们不会被执行(因为您已将它们转换为字符串);并且任何无效的日期值将导致0000.删除引号,它应该工作得很好。

INSERT INTO 
    Date_And_Time_In (Number_of_days, Date_In, Time_In)
    VALUES ('02', DATE(2013-06-03), TIME(12:10:00));

#2


0  

You don't need to put the DATE() and TIME() functions around those values. MySQL accepts those formats and puts them in correctly. See below:

您不需要在这些值周围放置DATE()和TIME()函数。 MySQL接受这些格式并将它们正确放入。见下文:

INSERT INTO Date_And_Time_In (Number_of_days, Date_In, Time_In) VALUES ('02', '2013-06-03', '12:10:00' );

#3


0  

You don't need the date and time functions. Just out the literals in quote.http://www.ntchosting.com/mysql/insert-date.html link has lots of example.

您不需要日期和时间功能。只需输出quote.http://www.ntchosting.com/mysql/insert-date.html链接中的文字就有很多例子。

#1


0  

When you add quotes around MySQL functions, they are not executed (because you have turned them into a string); and any invalid date value will result in 0000. Remove the quotes and it should work great.

当您在MySQL函数周围添加引号时,它们不会被执行(因为您已将它们转换为字符串);并且任何无效的日期值将导致0000.删除引号,它应该工作得很好。

INSERT INTO 
    Date_And_Time_In (Number_of_days, Date_In, Time_In)
    VALUES ('02', DATE(2013-06-03), TIME(12:10:00));

#2


0  

You don't need to put the DATE() and TIME() functions around those values. MySQL accepts those formats and puts them in correctly. See below:

您不需要在这些值周围放置DATE()和TIME()函数。 MySQL接受这些格式并将它们正确放入。见下文:

INSERT INTO Date_And_Time_In (Number_of_days, Date_In, Time_In) VALUES ('02', '2013-06-03', '12:10:00' );

#3


0  

You don't need the date and time functions. Just out the literals in quote.http://www.ntchosting.com/mysql/insert-date.html link has lots of example.

您不需要日期和时间功能。只需输出quote.http://www.ntchosting.com/mysql/insert-date.html链接中的文字就有很多例子。