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. Get check time from separate fields in Microsoft SQL Server

Get check time from separate fields in Microsoft SQL Server

Scheduled Pinned Locked Moved Database
questiondatabasesql-servercomsysadmin
5 Posts 4 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.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, I am using aloha POS and they have the date for every check in separate fields and now I want to calculate the total time for the checks but unable to get the how of it.. 1. The date is DOB and it's datetime but I just need to extra the getdate() from it. 2. The open time is OPENHOUR and OPENMIN 3. The close time is CLOSEHOUR and CLOSEMIN so basically the open time for the check will be the DATE FROM DOB + OPENHOUR + OPENMIN and the close time will be DATE FROM DOB + CLOSEHOUR + CLOSEMIN How can I get the total minutes for the check? Thanks, Jassim[^]

    Technology News @ www.JassimRahma.com

    M 1 Reply Last reply
    0
    • J Jassim Rahma

      Hi, I am using aloha POS and they have the date for every check in separate fields and now I want to calculate the total time for the checks but unable to get the how of it.. 1. The date is DOB and it's datetime but I just need to extra the getdate() from it. 2. The open time is OPENHOUR and OPENMIN 3. The close time is CLOSEHOUR and CLOSEMIN so basically the open time for the check will be the DATE FROM DOB + OPENHOUR + OPENMIN and the close time will be DATE FROM DOB + CLOSEHOUR + CLOSEMIN How can I get the total minutes for the check? Thanks, Jassim[^]

      Technology News @ www.JassimRahma.com

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      This might give you dome ideas, demonstrating the DATEADD and Convert Date possibilities

      DECLARE @DOB DATETIME = GETDATE()
      DECLARE @ODate DATE
      DECLARE @OHour INT = 8
      DECLARE @OMin INT = 23
      DECLARE @OpenDT DATETIME

      SELECT @ODate = CONVERT(DATE,@DOB)
      SET @OpenDT = @ODate
      SELECT @OpenDT = DATEADD(HOUR,@OHour,@OpenDT)
      SELECT @OpenDT = DATEADD(MINUTE,@OMin,@OpenDT)

      PRINT @OpenDT

      Never underestimate the power of human stupidity RAH

      C 1 Reply Last reply
      0
      • M Mycroft Holmes

        This might give you dome ideas, demonstrating the DATEADD and Convert Date possibilities

        DECLARE @DOB DATETIME = GETDATE()
        DECLARE @ODate DATE
        DECLARE @OHour INT = 8
        DECLARE @OMin INT = 23
        DECLARE @OpenDT DATETIME

        SELECT @ODate = CONVERT(DATE,@DOB)
        SET @OpenDT = @ODate
        SELECT @OpenDT = DATEADD(HOUR,@OHour,@OpenDT)
        SELECT @OpenDT = DATEADD(MINUTE,@OMin,@OpenDT)

        PRINT @OpenDT

        Never underestimate the power of human stupidity RAH

        C Offline
        C Offline
        Chris Quinn
        wrote on last edited by
        #3

        You can simplify slightly

        DECLARE @ODate DATE
        DECLARE @OHour INT = 8
        DECLARE @OMin INT = 23
        DECLARE @OpenDT DATETIME
        declare @DOB DATE = getdate() --Or whatever date drom the database
        SELECT @OpenDT = @DOB

        SELECT @OpenDT = DATEADD(MINUTE,(@OHour * 60) + @OMin, @OpenDT)

        PRINT @OpenDT

        ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

        Richard DeemingR 1 Reply Last reply
        0
        • C Chris Quinn

          You can simplify slightly

          DECLARE @ODate DATE
          DECLARE @OHour INT = 8
          DECLARE @OMin INT = 23
          DECLARE @OpenDT DATETIME
          declare @DOB DATE = getdate() --Or whatever date drom the database
          SELECT @OpenDT = @DOB

          SELECT @OpenDT = DATEADD(MINUTE,(@OHour * 60) + @OMin, @OpenDT)

          PRINT @OpenDT

          ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          You've declared @ODate as DATE, so you can't add time parts to it.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          C 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            You've declared @ODate as DATE, so you can't add time parts to it.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            C Offline
            C Offline
            Chris Quinn
            wrote on last edited by
            #5

            I'm adding the minutes to @OpenDT so it does work - @ODate is superfluous and can be removed

            ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

            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