Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Calculating the Time length

Calculating the Time length

Scheduled Pinned Locked Moved Database
databasesecurityhelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    minkinin
    wrote on last edited by
    #1

    Hi everyone. pls help,I am busy with the security access system which monitores arrival ,lunch and depature time,so I need to calculate the time length eg my table looks like this: Date Name TimeIN TimeOUT Length 12/2/2007 Myself 7:45 12:00 4:55 so how do I calculate that 4:55 which is the difference of TImeIN and TimeOUT,I need a sql statement or any calculation methods to do that. Thanks in advance.

    B G 2 Replies Last reply
    0
    • M minkinin

      Hi everyone. pls help,I am busy with the security access system which monitores arrival ,lunch and depature time,so I need to calculate the time length eg my table looks like this: Date Name TimeIN TimeOUT Length 12/2/2007 Myself 7:45 12:00 4:55 so how do I calculate that 4:55 which is the difference of TImeIN and TimeOUT,I need a sql statement or any calculation methods to do that. Thanks in advance.

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Hope this helps DECLARE @dd AS datetime SET @dd =(SELECT convert(datetime,TimeOUT) - convert(datetime,TimeIN)) SELECT convert(varchar,@dd,108) AS minutes

      M 1 Reply Last reply
      0
      • M minkinin

        Hi everyone. pls help,I am busy with the security access system which monitores arrival ,lunch and depature time,so I need to calculate the time length eg my table looks like this: Date Name TimeIN TimeOUT Length 12/2/2007 Myself 7:45 12:00 4:55 so how do I calculate that 4:55 which is the difference of TImeIN and TimeOUT,I need a sql statement or any calculation methods to do that. Thanks in advance.

        G Offline
        G Offline
        gauthee
        wrote on last edited by
        #3

        you can use the datediff function to dothis! first, get the differnce in hrs and then find the difference in minutes....

        Gautham

        1 Reply Last reply
        0
        • B Blue_Boy

          Hope this helps DECLARE @dd AS datetime SET @dd =(SELECT convert(datetime,TimeOUT) - convert(datetime,TimeIN)) SELECT convert(varchar,@dd,108) AS minutes

          M Offline
          M Offline
          minkinin
          wrote on last edited by
          #4

          thanks,but is still not working because the datatype of TimeIN and TimeOUT is Nvarchar not datetime,I did that because I wanted to insert them as DateTime.Now.ToShortDateString();so how will I manage to get the difference of nvarchar datype fields. help....

          B 1 Reply Last reply
          0
          • M minkinin

            thanks,but is still not working because the datatype of TimeIN and TimeOUT is Nvarchar not datetime,I did that because I wanted to insert them as DateTime.Now.ToShortDateString();so how will I manage to get the difference of nvarchar datype fields. help....

            B Offline
            B Offline
            Blue_Boy
            wrote on last edited by
            #5

            try converting fields TimeOUT and TimeIN in varchar datatype. DECLARE @dd AS datetime SET @dd =(SELECT convert(datetime,cast(TimeOUT as varchar)) - convert(datetime,cast(TimeIN as varchar))) SELECT convert(varchar,@dd,108) AS minutes

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups