+ Reply to Thread
Results 1 to 30 of 30

Date/time formula question.

  1. #1
    Registered User
    Join Date
    10-11-2007
    Posts
    16

    Date/time formula question.

    Hi all,

    Does anyone have a formula (or formulae) for working out the following:

    Don't hesitate to ask me more details, or contact me on MSN...

    I have a worksheet with one column showing date and time, in HH:MM (North American Format) and a second column showing temperature readings taken every 15 minutes.

    What I am trying to calculate is the total amount of time (in HH:MM) that the temperature was equal to or below a certain threshold.

    I have seen some formulaes for calculating elapsed time, but nothing which can account for this variable.

    Any help is greatly appreciated and you are guaranteed a free beer should you ever be in Copenhagen!

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    See if you can get this to work

    Please Login or Register  to view this content.

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Quote Originally Posted by VBA Noob
    See if you can get this to work

    Please Login or Register  to view this content.

    VBA Noob
    Hmmm, I am not sure that would do the trick.. I assumed I would need some sort of IF statement, i.e. IF B1:B1200 =<2,0 etc...

    But I am happy to be corrected.

    Also, on a side note, any idea why my version of Excel (2000 SP3) needs semi-colons as opposed to commas?...

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Post a sample of your file.

    You can set semi colon etc under Tools > options > international tab

    VBA Noob

  5. #5
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Thanks for that VBA Noob, but it returned a result of 0...

    Here is an example of the data as it is laid out (although I think I could modify this if needed)

    Date & Time Temp Reading

    2007-8-31 1:09 PM 3,2
    2007-8-31 1:11 PM
    2007-8-31 1:13 PM
    2007-8-31 1:15 PM
    2007-8-31 1:24 PM 3,3
    2007-8-31 1:26 PM
    2007-8-31 1:28 PM
    2007-8-31 1:30 PM
    2007-8-31 1:41 PM


    What I would like is a value somewhere which shows any deviations or exceptions from a specific value, in this case, 2,0. Once I can work out the calc, I can then make it whizzy on another sheet to flag deviations, or graph it, etc...

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Can you show the expected results as well so I'm clear

    PS

    calculate is the total amount of time
    This is a totally different question to your first

    VBA Noob

  7. #7
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    AHA!

    Occam's Razor is right again...

    As I know the temperature is taken every 15 minutes, and I have a reading, if I simply use something like:

    =CountIF(A1:A12,<=2.0)

    This would return the number of times it dropped below the threshold, and as I know readings are taken each 15 minutes, could I just not multiply it by 15, resulting in the total number of minutes... but then I need to know how to convert this numeric value into HH:MM

  8. #8
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Quote Originally Posted by VBA Noob
    Can you show the expected results as well so I'm clear

    PS



    This is a totally different question to your first

    VBA Noob

    Sorry.. I was struggling to work out how to express it as a question... (just moved here and sleep deprived still)...

  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Maybe

    =COUNTIF($B$1:$B$12,">=2")*15/1440
    format as time

    VBA Noob

  10. #10
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Quote Originally Posted by VBA Noob
    Maybe



    format as time

    VBA Noob
    Hmm close.. but it returns a result of 1:01 for a 60 minute period... may I ask why we divide by 1440? I have seen it in other time/date formulae, and was curiouse... btw, thanks for the help apologies if these are simple questions..

  11. #11
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    See link re time

    http://www.ozgrid.com/Excel/date-time-calculations.htm

    On my attachment I got 30 mins. 2 x 15

    VBA Noob
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Hmmm, when I opened your example I got, 12:30:00 AM

    I think I may have worked it out using:

    =CONCATENATE(ROUND(ROUND(((B1231)*1440);0)/1440/60;0);" Hours
    ";TRUNC(MOD(ROUND((B1231)*1440;0);1440)/60);" Minutes
    ")


    Where B1231 is the formula: =COUNTIF(B3:B1227;"<2")*15


    Just checking my results manually now...

  13. #13
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Hmmm, something seems askew, I think it's a simple fix as if I increase the value and expect the time to move by 15 minutes, it moves by one hour... must be something in the calc...

  14. #14
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    You will do because of the , and ;

    You need to change in options as I mentioned

    VBA Noob

  15. #15
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Quote Originally Posted by VBA Noob
    You will do because of the , and ;

    You need to change in options as I mentioned

    VBA Noob

    Are you sure? I would not have thought that would make a difference as Excel is just seeing ; as a , so it should be ok...

  16. #16
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    This is what it looks like to me.

    VBA Noob
    Attached Images Attached Images

  17. #17
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Quote Originally Posted by VBA Noob
    You will do because of the , and ;

    You need to change in options as I mentioned

    VBA Noob

    Are you sure? I would not have thought that would make a difference as Excel is just seeing ; as a , so it should be ok...

  18. #18
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Aha, interesting, I have no International settings option...

    At any rate here is the formulae I am using...

    Formula 1

    =COUNTIF(B3:B1227;"<2")*15

    This gives me the amount of minutes the deviation occured


    Formula 2

    =CONCATENATE(ROUND(ROUND(((B1231)*1440);0)/1440/60;0);" Hours
    ";TRUNC(MOD(ROUND((B1231)*1440;0);1440)/60;0);" Minutes
    ")

    This is supposed to give me the number of minutes neatly displayed in Hours and Minutes, however; what is happening is that if another deivation occurs, the hours progress but not the minutes...

    Can anyone think of the problem, or perhaps recommend another formula to display xxxxx minutes as xxh xx min?

    BTW, don't worry about the semi-colons, they function as commas do in the North American version... and I would prefer not to change this as the end users won't have the wherewithal to change their settings...

  19. #19
    Registered User
    Join Date
    10-11-2007
    Posts
    16

    Simple Hour/Minute conversion?

    I will try a different question...

    Is there a simple way to take a cell which is showing 46.25 to show this as 46 hours and 15 minutes?

    Or 46.5 as 46 hours and 30 minutes, etc?

    Thanks!

  20. #20
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Thanks for moving this into the same thread.. I suppose I was being a little cheeky starting a new one...

    At any rate, anyone have an idea?

  21. #21
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    If you have 46.25 in A1 then try

    =TEXT(A1/24;"[h] \hour\s m \mi\nut\e\s")

    If you want to work directly with the number of minutes, i.e. A1 contains 2775 change the formula to

    =TEXT(A1/1440;"[h] \hour\s m \mi\nut\e\s")
    Last edited by daddylonglegs; 10-11-2007 at 08:29 AM.

  22. #22
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    also:

    =INT(A1) & " hours and " & MOD(A1,1)*60 & " minutes"
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  23. #23
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    Thanks for that, but no luck, I got a VALUE error...

    I did work out the formula to show it as hh:mm, which is:

    =SUM(COUNTIF(B3:B1227;"<2")*15)/(24*60)

    With the cell formatted to Custom, [t]:mm

    But my preference would be to show xx Hours xx minutes

  24. #24
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by NBVC
    also:

    =INT(A1) & " hours and " & MOD(A1,1)*60 & " minutes"
    That's also a good way but you might need to include some rounding element because 46.6 in A1 would give a result like

    46 hours 36.0000000000001 minutes

    so I'd change to

    =INT(A1) & " hours and " & ROUND(MOD(A1,1)*60,0) & " minutes"

  25. #25
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898
    Quote Originally Posted by daddylonglegs
    That's also a good way but you might need to include some rounding element because 46.6 in A1 would give a result like

    46 hours 36.0000000000001 minutes

    so I'd change to

    =INT(A1) & " hours and " & ROUND(MOD(A1,1)*60,0) & " minutes"
    Thank daddylonglegs...you're right... I only tested the sample given...should've played with it a bit

  26. #26
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by Scootter_DK
    Thanks for that, but no luck, I got a VALUE error...

    I did work out the formula to show it as hh:mm, which is:

    =SUM(COUNTIF(B3:B1227;"<2")*15)/(24*60)

    With the cell formatted to Custom, [t]:mm

    But my preference would be to show xx Hours xx minutes
    Do you mean using TEXT function? I don't know if that'll work correctly with a non-English version of Excel. Try modifying NBVC's suggestion, i.e.

    =INT(COUNTIF(B3:B1227;"<2")/4)&" hours "&ROUND(MOD(COUNTIF(B3:B1227;"<2")*15;60);0)&" minutes"

  27. #27
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    YAHOOO!

    Daddylonglegs, if you are ever in Copenhagen let me know, beer is on me!


  28. #28
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Having looked a bit closer then given that your number of minutes is based on a COUNTIF which can only return whole minutes and therefore the final result is always a multiple of 15 minutes, you don't need ROUND function, so my previous version should work but you can shorten to

    =INT(COUNTIF(B3:B1227;"<2")/4)&" hours "&MOD(COUNTIF(B3:B1227;"<2");4)*15&" minutes"

  29. #29
    Registered User
    Join Date
    10-11-2007
    Posts
    16
    OK great, thanks again.

    As I just started with this company, it's a chance to make a good and helpful impression on my colleagues.

  30. #30
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    Quote Originally Posted by Scootter_DK
    I did work out the formula to show it as hh:mm, which is:

    =SUM(COUNTIF(B3:B1227;"<2")*15)/(24*60)

    With the cell formatted to Custom, [t]:mm

    But my preference would be to show xx Hours xx minutes
    Final thoughts....

    Your suggestion here is probably a better approach actually, because the result, while showing as a time, is still a value, so you can use it for calculations. You should be able to use the simpler formula

    =COUNTIF(B3:B1227;"<2")/96

    and custom format that cell as

    [t] "hours" m "minutes"

    [I assume "t" is Danish notation for hours?]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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