Results 1 to 4 of 4

Thread: [RESOLVED] DateTime Format in SQL to Get Time Difference

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Location
    AZ
    Posts
    67

    Resolved [RESOLVED] DateTime Format in SQL to Get Time Difference

    I have two fields in a record
    RespStart and RespEnd in a DateTime format...

    When I type in 01:AM and 01:05AM into each field respectavley.. the values change to 01:01:00AM and 01:05:00AM

    I am trying to grab the total time from Start to End. When I query the table I get this format in the View

    RespStart = 1899-12-30 01:01:00.000
    RespEnd = 1899-12-30 01:05:00.000

    (RespEnd-RespStart) = 1900-01-01 00:00:00.000


    Is there a format to grab the Time values and get the difference from that and / or also change the date field to the current date if needed but mainly I want to get the time format to get the time between
    RespStart and RespEnd


    Thank you,

    --the first two SQL are test to see the values put out
    (Select RespStart From TBLBAT_ALARMINC Where AlarmTypeID = 1 AND BatchID = m.BatchID AND ModemID = a.ModemID) AS RespStart,

    (Select RespEnd From TBLBAT_ALARMINC Where AlarmTypeID = 1 AND BatchID = m.BatchID AND ModemID = a.ModemID) AS RespEnd,


    --This should be the value to grab the time used
    (Select (RespEnd - RespEnd) From TBLBAT_ALARMINC Where AlarmTypeID = 1 AND BatchID = m.BatchID AND ModemID = a.ModemID) AS RespTime

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: DateTime Format in SQL to Get Time Difference

    Use the DateDiff function... you can specify if you want seconds 's' minutes 'n' hours 'h', days, etc...

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Location
    AZ
    Posts
    67

    Smile Re: DateTime Format in SQL to Get Time Difference

    I put in

    (Select DateDiff(n,RespEnd,RespEnd) From TBLBAT_ALARMINC Where AlarmTypeID = 1 AND BatchID = m.BatchID AND ModemID = a.ModemID) AS RespTime

    yet the value returned is Zero...

    n being the interval of Minute


    the date value still come out 1899-12-30 01:01:00.000 and
    1899-12-30 01:05:00.000

    with the RespTime (as above) is 0


    not sure how to change the date part since it's not December of 1899
    but I would like to get the time difference..

    Thanks for any imput

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: DateTime Format in SQL to Get Time Difference

    Just like 1-1 will always be 0... so will this: DateDiff(n,RespEnd,RespEnd)

    Try DateDiff(n,RespStart,RespEnd) instead....

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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