|
-
May 16th, 2007, 08:28 AM
#1
Thread Starter
Fanatic Member
SQL Time Issue
Hey there,
i've just noticed a big problem in my SQL table.
inside the table we have the following fields:
tbl_Arrivals
iId - int identity eg: 1
dArrivalDate - smalldatetime eg: 01/01/2007
sArrivalSchdeduledTime - nvarchar(5) eg: 23:35
sArrivalActualTime - nvarchar(5) eg: 00:15
I have to do a report in my table to establish the length of mins each arrival was late.
so basically sArrivalActualTime - sArrivalSchdeduledTime
which i was doing using the following SQL
DATEDIFF(mi, CAST(sArrivalActualTime AS DateTime),
CAST(sArrivalSchdeduledTime AS DateTime))
now this works fine when the time doesn't go past 23:59.
but for the example data above it will cause serious issues.
has anyone come across a solution to this before.
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 16th, 2007, 08:38 AM
#2
Re: SQL Time Issue
Wouldn't you need a field for the actual arrival date (as in you example it was supposed to arrive on Monday at 23:35 but actually arrived on Tuesday at 00:05. They are two different dates.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
May 16th, 2007, 10:10 AM
#3
Hyperactive Member
Re: SQL Time Issue
You might want to consider storing the date and time together. You could have
ScheduleArrival
ActualArrival
both as date times. It will make your datetime manipulation much easier!
-
May 16th, 2007, 02:02 PM
#4
Re: SQL Time Issue
I agree with The_Duck.
An arrival is always on a date and time, so you should change your design to store the scheduled and actual arrival as datetime or smalldatetime, depending on the resolution you need. I would guess smalldatetime should do it for you.
-
May 16th, 2007, 05:47 PM
#5
Thread Starter
Fanatic Member
Re: SQL Time Issue
Thanks guys for the replies... the more i thought about it the more i came to the conclusion that it couldn't be done.
I just said i'd post in hope.
At the beginning of the project i didn't expect them to be wanting to comparing the times i was storing as strings.
The way the application i have was just one date and then drop downs for hours and minutes. hmmmm i will have to make some changes
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
|