Reputation: 143
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?
Upvotes: 0
Views: 94
Reputation: 10895
This works with MS SQL 2012: Fiddle Demo
SELECT DATEADD(HH,-1 ,CAST(stringTime as time)) FROM myTable
Upvotes: 1
Reputation: 279
For SQL Server, you can use the following query:
select dateadd(hh,-1 ,cast(timecolumn as time)) from tablename
Upvotes: 2
Reputation: 780724
If using MySQL, use DATE_SUB
to subtract a time period.
SELECT DATE_SUB(timefield, INTERVAL 1 HOUR) AS timefield_minus_hour
Upvotes: 1