[RESOLVED] Convert NVarchar(5) to a Time
Hi there,
i am storing a time in my table as a nvarchar(5) field. I used a this as i dont care about the date and just want the time. I dont know if this is a good idea or not.
but now i need to do a SELECT on the fields ScheduledArrivalTime and ActualArriveTime and compare them the time difference in Minutes.
How can i do this?
SELECT * FROM tbl_MyTable WHERE
ScheduledArrivalTime - ActualArriveTime > 60
Re: Convert NVarchar(5) to a Time
Give an example of the value that is stored in ScheduledArrivalTime
Re: Convert NVarchar(5) to a Time
ScheduledArrivalTime would be 22:00
ActualArriveTime would be 23:25
i would probably need to convert it to a date and get the datediff in minutes
Re: Convert NVarchar(5) to a Time
Try this (put the column name and from clause)
Code:
Select DateDiff("hh",Cast('22:00'as datetime),cast('23:25' as datetime))
Re: Convert NVarchar(5) to a Time
how come the DateDiff clause is not allowed in the WHERE part of the statement.
this is what im trying to do
SELECT *
FROM tbl_Despatches
WHERE DATEDIFF(mm, CAST(sATA AS DateTime), CAST(sSTA AS DateTime)) >= 60
i want to display all records that have delays of 60 minutes or more
Re: Convert NVarchar(5) to a Time
Use Datediff ("mi or n" ...) instead of mm
mm is for month
Re: Convert NVarchar(5) to a Time
ah ok that worked... i had missing brackets