Results 1 to 7 of 7

Thread: [RESOLVED] Convert NVarchar(5) to a Time

  1. #1

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

    Resolved [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

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: Convert NVarchar(5) to a Time

    Give an example of the value that is stored in ScheduledArrivalTime

  3. #3

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

    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

  4. #4
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    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))

  5. #5

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

    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

  6. #6
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: Convert NVarchar(5) to a Time

    Use Datediff ("mi or n" ...) instead of mm
    mm is for month

  7. #7

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

    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
  •  



Click Here to Expand Forum to Full Width