locked
how-to make a combined date and hour counter RRS feed

  • Question

  • User2113851930 posted

    How do I put hours in this code, I want a specific Clock to be incorporated in my code, so the shift is on days and at a given clock,
    instead of at midnight as in my code below

    ect. wednesday 2 february 11 O'Clock to 9 february 11 O'Clock

    (As you can see in my code it happen again and again every third weeks)

    DateTime startdate = new DateTime(2013, 2 , 12, 11, 00, 0);
    DateTime todaydate = DateTime.Now.Date;
    TimeSpan t = todaydate - startdate;
    int days = (int)t.TotalDays;  

        if ((days % 21 <= 6) && (days % 21 > -1))                                {                                                                                                                                   

    something happens...

         }

     

     I can explain it better.
    As you can see in my code my start date is (2013, 2, 12) 11 O'clock.
    As you can see the code shift every third weeks "if ((days % 21 <= 6) && (days % 21 > -1))".   "7 days act"
    What I want is that it shift exactly on 11 O'clock.
    Example: start (2013, 2 , 12, 11, 00, 0) and end at (2013, 9 , 12, 10, 59, 59), as you can see  exactly 7days span

    Wednesday, June 26, 2013 8:20 AM

All replies

  • User-1373950060 posted

    Hi,

    For check the times please use:

    TimeSpan start = new TimeSpan(10, 59, 0); //10:59 o'clock
    TimeSpan end = new TimeSpan(11, 1, 0); //11:01 o'clock
    TimeSpan now = DateTime.Now.TimeOfDay;
    
    if ((now > start) && (now < end))
    {
       //match found
    }

    Hope that's helpful.

    Thursday, June 27, 2013 3:58 AM
  • User2113851930 posted

    Thanks Chunyan Yu -... 

    well what I want is to incorporate it in my day count code, and I can't see how I can do this ?

    It should be combined (day and hours)

     

     I can explain it better. As you can see in my code my start date is (2013, 2, 12) 11 O'clock.
    As you can see the code shift every third weeks "if ((days % 21 <= 6) && (days % 21 > -1))".   "7 days act"

    What I want is that it shift exactly on 11 O'clock.
    Example: start (2013, 2 , 12, 11, 00, 0) and end at (2013, 9 , 12, 10, 59, 59), as you can see  exactly 7days span

    Thursday, June 27, 2013 6:00 AM