Results 1 to 5 of 5

Thread: SQL Time Issue

  1. #1

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    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

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    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

  3. #3
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    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!

  4. #4
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    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.

  5. #5

    Thread Starter
    Fanatic Member Strider's Avatar
    Join Date
    Sep 2004
    Location
    Dublin, Ireland
    Posts
    612

    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
  •  



Click Here to Expand Forum to Full Width