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. General Programming
  3. C#
  4. Date And Time

Date And Time

Scheduled Pinned Locked Moved C#
csharpcomquestion
3 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
    Muhammad Waqas Butt
    wrote on last edited by
    #1

    Hi Everybody, Can anyone tell me how we can calculate working hours base on two intervals of time. like Starting Date: 17-05-2006 09:00 AM - Ending Date: 17-05-2006 05:00 PM ? If ending date something like this then what to do? Starting Date: 17-05-2006 09:00 AM - Ending Date: 18-05-2006 08:00 AM I'm using C#.Net |Muhamad Waqas Butt| waqasb4all@yahoo.com www.sktech.freewebspace.com

    N 2 Replies Last reply
    0
    • M Muhammad Waqas Butt

      Hi Everybody, Can anyone tell me how we can calculate working hours base on two intervals of time. like Starting Date: 17-05-2006 09:00 AM - Ending Date: 17-05-2006 05:00 PM ? If ending date something like this then what to do? Starting Date: 17-05-2006 09:00 AM - Ending Date: 18-05-2006 08:00 AM I'm using C#.Net |Muhamad Waqas Butt| waqasb4all@yahoo.com www.sktech.freewebspace.com

      N Offline
      N Offline
      NaNg15241
      wrote on last edited by
      #2

      if you use it as variables of type DateTime then it's not problem. search the commands and static commands between DateTime, and most importent TimeSpan (TimeSpan - Represents Time intervals), I suggest the TimeSpan\DateTime parse method, and TimeSpan.Substract method. if you are still having troubles I'll give you a sample code.

      1 Reply Last reply
      0
      • M Muhammad Waqas Butt

        Hi Everybody, Can anyone tell me how we can calculate working hours base on two intervals of time. like Starting Date: 17-05-2006 09:00 AM - Ending Date: 17-05-2006 05:00 PM ? If ending date something like this then what to do? Starting Date: 17-05-2006 09:00 AM - Ending Date: 18-05-2006 08:00 AM I'm using C#.Net |Muhamad Waqas Butt| waqasb4all@yahoo.com www.sktech.freewebspace.com

        N Offline
        N Offline
        NaNg15241
        wrote on last edited by
        #3

        for your request (I got the email... but there is no msg here, so if I would post there you wouldn't get the email notification). I've built this method, a small method that all you need is two datetimes...

        private TimeSpan SubTime(DateTime dt1, DateTime dt2)
        {
            // Substracts dt1 from dt2
            TimeSpan ts = TimeSpan.Parse(dt2.ToString("H:mm:ss"));
            return ts.Subtract(TimeSpan.Parse(dt1.ToString("H:mm:ss")));
        }
        

        now you use it like this: DateTime dateDiff = DateTime.Parse(SubTime(DateTime.Now, DateTime.Now.AddHours(3))); simple no? btw I think DateDiff is in SQL... this is C#. if you want to pick datetime you can use the datetimepicker that has alot of functionality, and very comfort, if you want to display the DateTime you just do in a label, Text property = DateTime1.ToString("formatting") eg. DateTime1.ToString("dd-month-yyyy hh:mm AM/PM") // just built it for you from a book I have - needed to custom make some stuff.... should work and if theres a problem try to search it, or if theres a real problem send me a msg... Hope I helped :D NaNg.

        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