简体   繁体   中英

Add An Hour To TIME Datatype

UPDATE Game
SET endTime = (SELECT DATEADD(hh, 1, startTime)
FROM GameInfo
WHERE Game.idGame = GameInfo.idGame);

I want to set the hours of endTime to be 1 hour later than the startTime, when I run this code I get the error:

ERROR 1728 (HY000): Cannot load from mysql.proc. The table is probably corrupted

I believe this is because the startTime and endTime fields are both of datatype TIME, but I can't seem to find a similar function for TIME datatype?

UPDATE Game
SET endTime = (SELECT HOUR(startTime)+1
FROM GameInfo
WHERE Game.idGame = GameInfo.idGame);

Will almost work, in that it does increment the hours, but then it saves just the hours as a number (resulting in 00:00:19 etc. for all entries).

Any help would be most appreciated!

Thanks.

您正在寻找的是: DATE_ADD(startTime, INTERVAL 1 HOUR)

In SQL Server, you can do something like this:

UPDATE g
    SET endTime = DATEADD(hour, 1, gi.startTime)
FROM Game g JOIN
     GameInfo gi
     ON g.idGame = gi.idGame;

Regardless of the database, I find it strange that the end time is in a different table from the start time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM