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. Working with only Time in Sql?

Working with only Time in Sql?

Scheduled Pinned Locked Moved Database
databasetutorialquestioncareer
2 Posts 2 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
    majidbhutta
    wrote on last edited by
    #1

    i have some confusion. Scenario is that for an Employee to start and end job the following fields are available; Field DataType ===== ======== Emp_Id Foreign Key} DateTime PrimaryKey }----> Composite Primary key CheckInTime DateTime CheckOutTime DateTime InOutStatus bit HoursWorked ?--------> What shoulud be DataType? When an Employee Checks in All fields are set and InOutStatus is set to 1 Except CheckOutTime and HoursWorked.When The Employee checks out InOutStatus is set to 0,CheckOutTime is set and then i have to calculate the HoursWorked (TimeDuaration). Constarins are CheckOutTime is always greater than CheckInTime.(There may be different dates for them as employee gets check in ,Nov 29,2005 on time 17:00 and checksout , Nov 30,2005 on time 03:30).Now according to calculation he worked for 10 hours and 30 minutes .How to calculate this hours worked(only time duration and to which datatype it should be saved in sql) as well as the Stored Procedure for this whole process.Whenever Employee comes his Emp_Id is only known. Thnx in Advance.

    F 1 Reply Last reply
    0
    • M majidbhutta

      i have some confusion. Scenario is that for an Employee to start and end job the following fields are available; Field DataType ===== ======== Emp_Id Foreign Key} DateTime PrimaryKey }----> Composite Primary key CheckInTime DateTime CheckOutTime DateTime InOutStatus bit HoursWorked ?--------> What shoulud be DataType? When an Employee Checks in All fields are set and InOutStatus is set to 1 Except CheckOutTime and HoursWorked.When The Employee checks out InOutStatus is set to 0,CheckOutTime is set and then i have to calculate the HoursWorked (TimeDuaration). Constarins are CheckOutTime is always greater than CheckInTime.(There may be different dates for them as employee gets check in ,Nov 29,2005 on time 17:00 and checksout , Nov 30,2005 on time 03:30).Now according to calculation he worked for 10 hours and 30 minutes .How to calculate this hours worked(only time duration and to which datatype it should be saved in sql) as well as the Stored Procedure for this whole process.Whenever Employee comes his Emp_Id is only known. Thnx in Advance.

      F Offline
      F Offline
      Farhan Noor Qureshi
      wrote on last edited by
      #2

      If minute level precision is fine then save the number of minutes and use int as datatype. Declare @dt1 datetime, @dt2 datetime Set @dt1 = GetDate() Set @dt2 = DateAdd(yyyy, 1, @dt1) select DATEDIFF(mi, @dt1, @dt2) Farhan Noor Qureshi if (this == this) thow this;

      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