+ Reply to Thread
Results 1 to 24 of 24

Adding 10 minutes to current time - issue at midnight

  1. #1
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Adding 10 minutes to current time - issue at midnight

    Hi all,

    In one of the spreadsheets there is a need to have a 'action at' field.

    This is the next five minute time slot between 5 and 10 minutes in the future (eg 10.51 -> 11.00 , 1.56 ->2.05 etc)

    this is fine using this formula

    Please Login or Register  to view this content.
    'DATE_TO_USE' is the day we should use (changes after 23.50)

    Please Login or Register  to view this content.
    these combined work fine for every period from 00.00 to 23.54.59 but in the next five minute period point to 00.05 on the current day (as opposed to day + 1)

    Can anybody see why this is?

    Thanks in advance

    Alex
    Last edited by thorne_; 05-12-2009 at 04:27 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding 10 minutes to current time - issue at midnight

    Are you using VBA?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    no - these are embedded within cells

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Adding 10 minutes to current time - issue at midnight

    I'm not entirely sure I follow... but

    B2: =MOD(FLOOR(A2+"00:10","00:05"),1)

    Where A2 holds time to which 10 minutes are added, the prior 5 minute point will be returned... the MOD will handle the midnight issue... ie if A2 is 23:56 B1 would return 00:05

  5. #5
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    thanks for your reply, but it wont return the correct date-time will it?

    eg using todays date (11 may) at 23.51 it should return '2009-May-12 00:00:00'

    and does but at 23.55 it returns '2009-May-11 00:00:00'

    which is a problem

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Adding 10 minutes to current time - issue at midnight

    It's still difficult for me at least to visualise your setup... if you're trying to find the last 5 minute period for NOW + ten minutes then:

    =FLOOR(NOW()+"00:10","00:05")

    (NOW() is a DateTime value so you merely need to add ten minutes to it and adjust thereafter - the result of which will equally be a DateTime value, the Day portion will adjust as it crosses midnight)
    Last edited by DonkeyOte; 05-11-2009 at 07:23 AM.

  7. #7
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    again thanks for your reply, that works for 23.55 - 00.00 but before that (from 11.50) it returns one day too much

    eg @ 23.51 it return 2009-May-13 00.00.00

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Adding 10 minutes to current time - issue at midnight

    post a sample file... I can't comprehend how you're getting 13th May based on NOW() + 10 mins.

  9. #9
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    hi,

    I attached a sample - the left values are yours, the right values are what is there currently.

    i replaced several parameters with constants and made the updatetime = now()
    Attached Files Attached Files

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Adding 10 minutes to current time - issue at midnight

    No doubt I sound like a bore but can you explain each cell - I can't make head nor tail of it I'm afraid...

    Re:
    G5: =ROUND(FLOOR(NOW()+"00:10","00:05"),0)

    By Rounding to 0 decimals you are dispensing with Time altogether and using only a Day value. In XL dates are Integers and Time is Decimal... ie Noon on 11th May = 39944.5
    (the above value for today noon assumes 1904 Date System in Use)

    If you round to nearest whole number (ie 0) you dispense with time... going back to your original point re: 13th May ... if the time portion of the value pre-rounding was >= noon you will end up rounding up to the next day given 0.5 (noon) will round to 1 where 1 equates to 1 entire day... if the time were < noon then it would round down to 00:00 of the same day.

  11. #11
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    Hi,

    the reason i used round is because i only need to get the day to use. Try using it without the round in there, it goes crazy!

    The original code wasn't written by me (i just have to attempt to fix the error)
    so i'm not 100% on it either

    I'm not sure about the reference to '<=0.999988426' but im assuming it denotes midnight of something along those lines. The other logical test in the formula i have adjusted - it is simply a test to ensure that the update time is in the past. If both these are true we add one day and use this as our day value in the second formula.

    Hope this clears it up a bit

    edit : 0.999988426 = (11:59:59 P.M.)
    Last edited by thorne_; 05-11-2009 at 09:10 AM.

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Adding 10 minutes to current time - issue at midnight

    As advised don't use ROUND use INT to extract the date of the datetime value given the former will actually increase the day by 1 whenever the time portion of the datetime value is greater than or equal to noon.

    Consider: X is 39944.5 (11th May Noon)

    ROUND(X,0) --> 39945 --> 12th May
    INT(X) --> 39944 --> 11th May

  13. #13
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    thanks, however there is still an issue from 23.49.59 to 23.54.59 where it jumps to 13th may!

  14. #14
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Adding 10 minutes to current time - issue at midnight

    I'm afraid I'm going to have to bow out as I'm finding it impossible to follow what it is you're doing / trying to do. Perhaps a fresh set of eyes will help.

  15. #15
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    ok - thanks for your help

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Adding 10 minutes to current time - issue at midnight

    Maybe =CEILING(A1+"0:05", "0:05")
    Entia non sunt multiplicanda sine necessitate

  17. #17
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    still get that weird 13th may value!

  18. #18
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Adding 10 minutes to current time - issue at midnight

    I don't:
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    try setting your time to between 23.55 and 23.59.59

  20. #20
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Adding 10 minutes to current time - issue at midnight

    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    mhmmm ok, my apologies - i wonder why it doesn't work for me - can i get the xls with your solution in?

    Thanks for your help

  22. #22
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Adding 10 minutes to current time - issue at midnight

    Attached ...
    Attached Files Attached Files

  23. #23
    Registered User
    Join Date
    05-11-2009
    Location
    dublin,ireland
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Adding 10 minutes to current time - issue at midnight

    thanks for your help

  24. #24
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Adding 10 minutes to current time - issue at midnight

    You're welcome. Would you please mark the thread as Solved?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1