简体   繁体   中英

Take 1 hour from time field

I have an time field which is in string format 'varchar' and I wish to convert this field to a time and take an hour from the converted value so that if I have 14:22 in the field I would get 13:22 in the converted value. How would I do this in a view?

对于SQL Server,可以使用以下查询:

select dateadd(hh,-1 ,cast(timecolumn as time)) from tablename

如果使用MySQL,请使用DATE_SUB减去一个时间段。

SELECT DATE_SUB(timefield, INTERVAL 1 HOUR) AS timefield_minus_hour

This works with MS SQL 2012: Fiddle Demo

SELECT DATEADD(HH,-1 ,CAST(stringTime as time)) FROM myTable

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