|
-
May 3rd, 2007, 05:42 AM
#1
Thread Starter
Fanatic Member
[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
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
May 3rd, 2007, 05:46 AM
#2
Re: Convert NVarchar(5) to a Time
Give an example of the value that is stored in ScheduledArrivalTime
-
May 3rd, 2007, 05:50 AM
#3
Thread Starter
Fanatic Member
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
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
May 3rd, 2007, 06:03 AM
#4
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))
-
May 3rd, 2007, 06:13 AM
#5
Thread Starter
Fanatic Member
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
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
May 3rd, 2007, 06:17 AM
#6
Re: Convert NVarchar(5) to a Time
Use Datediff ("mi or n" ...) instead of mm
mm is for month
-
May 3rd, 2007, 06:17 AM
#7
Thread Starter
Fanatic Member
Re: Convert NVarchar(5) to a Time
ah ok that worked... i had missing brackets
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|