I need to subtract time values in a column type time - only hours minutes , seconds are inserted no days or months- to a certain numbers to make different timezones
我需要在列类型时间中减去时间值 - 只有小时分钟,插入的秒数,没有天或月 - 到某个数字来制作不同的时区
when I use for example
当我使用例如
SELECT subtime('01:00:00', "9:30:00")
it returns
它返回
-08:30:00
-08:30:00
on the other hand if I switch them to subtime( "9:30:00" , '01:00:00') it returns
另一方面,如果我将它们切换到子时间(“9:30:00”,“01:00:00”),它将返回
08:30:00 while the required value should be 3:30:00
08:30:00,所需价值应为3:30:00
how can I subtract time without getting minus ?
如何减去时间而不减去?
2 个解决方案
#1
0
How about something like this?
这样的事怎么样?
SELECT IF(CAST('01:00:00' AS TIME) > CAST('9:30:00' AS TIME), SUBTIME('01:00:00', '9:30:00'), SUBTIME('9:30:00', '01:00:00'));
#2
0
To subtract (2) different times:
要减去(2)不同的时间:
SELECT TIMEDIFF(time_out, time_in);
To add (2) different times:
添加(2)不同的时间:
SELECT ADDTIME(time1, time2);
For more Date and Time Functions, go here https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
有关更多日期和时间函数,请访问https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
#1
0
How about something like this?
这样的事怎么样?
SELECT IF(CAST('01:00:00' AS TIME) > CAST('9:30:00' AS TIME), SUBTIME('01:00:00', '9:30:00'), SUBTIME('9:30:00', '01:00:00'));
#2
0
To subtract (2) different times:
要减去(2)不同的时间:
SELECT TIMEDIFF(time_out, time_in);
To add (2) different times:
添加(2)不同的时间:
SELECT ADDTIME(time1, time2);
For more Date and Time Functions, go here https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
有关更多日期和时间函数,请访问https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html