What you wanted to know about Time values
I tried to gather in a single document the useful infos about the use of time values in Numbers.
I must thanks pw1840 which checked the English syntax.
Here is the text only document.
Files with the sample tables are available on my iDisk:
<http://idisk.me.com/koenigyvan-Public?view=web>
Download:
For iWork:ForNumbers:Time in Numbers.zip
*STORED DATE-TIME VALUES - BASICS*
Numbers clearly states that it stores date-time values, no less no more. This means these values consist of two parts: a date and a time. It is important to note that both parts are present even if only one of them is displayed.
When we type the time portion only, it includes the current date even though it may not be displayed.
But when we apply the formula: =TIME(0,0,ROUND(TIMEVALUE(B) 24*6060,0)), we get a date-time value whose numerical value of the date portion is 0. This means, in AppleLand, 1 janvier 1904. Such a date-time allows us to make correct calculations, but there are two true drawbacks:
1) Since TIMEVALUE() returns a decimal number, when we calculate the corresponding number of seconds we MUST use the ROUND() function. While calculations with decimal numbers give the wanted value, they may not be exact and be off by + or - epsilon. And
2) The structure of Numbers date-time values is such that the time part is always in the range 0:00:00 thru 23:59:59.
There is also a detail which seems annoying to some users. The minimal time unit is the second because time values are in fact a pseudo string representing the number of seconds between the date-time and the base date-time, 1 janvier 1904 00:00:00.
-+-+-+-+-
*TIMEVALUE() FUNCTION*
When Numbers Help states that the TIMEVALUE() function "converts a date, a time, or a text string to a decimal fraction of a 24-hour day.", it means that the operand for the function TIMEVALUE() may be something like:
31/12/1943, 31 décembre 1943, or 31 déc. 1943 described as a date;
1:12:36 or 1:12 described as time; or
31/12/1943 23:59:59 described as a text string.
The date may also be 31/12/43 but here the program must guess the century. According to the rule, this one will be 31/12/2043 (yes, I am very young).
All of this is not exactly what we are accustomed to but it is perfectly logical as described. My guess is that those who don't understand are simply clinging to old habits and are reluctant to adopt an unfamiliar approach .
-+-+-+-+-
*ELAPSED TIME (DURATION)*
Given a table whose 1st row is a header, I will assume that column B stores starting-time values and column C stores ending-time values. Both do not display the date component of the date-time values. We may get the difference in column D with the formula:
=IF(OR(ISBLANK(B),ISBLANK(C)),"",TIMEVALUE(C)-TIMEVALUE(B))
which returns the elapsed time as the decimal part of the day.
We immediately encounter a problem. If ending-time is the day after the starting-day, the result will be negative. So it would be useful to revise the formula this way:
=IF(OR(ISBLANK(B),ISBLANK(C)),"",IF(TIMEVALUE(C)>TIMEVALUE(B),0,1)+TIMEVALUE(C) -TIMEVALUE(B))
But some of us may wish to see results in the traditional format which may be achieved using:
=IF(OR(ISBLANK(B),ISBLANK(C)),"",TIME(0,0,ROUND((IF(TIMEVALUE(C)>TIMEVALUE(B),0 ,1)+TIMEVALUE(C)-TIMEVALUE(B)) 24*6060,0)))
-+-+-+-+-
*DURATION SUMS > or = 24 HOURS*
In the examples above, we always assumed that the durations where smaller than 24 hours because Numbers states clearly in the Help and the PDF Users Guide that time values are restricted to the range 00:00:0 to 23:59:59. For longer durations we must fool Numbers.
First problem: we are adding several time durations. Each duration is in the authorized range and the result is greater than 24 hours.
As before, starting-time values are in column B, ending-time ones are in column C, and the elapsed time value is in column D. The formula is:
=IF(OR(ISBLANK(B),ISBLANK(C)),"",IF(TIMEVALUE(C)>TIMEVALUE(B),0,1)+TIMEVALUE(C) -TIMEVALUE(B))
in column E, the formula for the cumulative elapsed time value is:
=SUM($D$2:D2)
in column F, converting to time format, the formula is:
=TIME(0,0,ROUND(MOD(E,1) 24*6060,0))
in column G, the formula for showing more than 24 hours in the day/hour/minute format is:
=IF(E<1,"",INT(E)&IF(E<2," day "," days "))&F
in column H, expressing total elapsed time in total hours using the traditional time format, the formula is:
=IF(E<1,F,INT(E)*24+LEFT(F,LEN(F)-6)&RIGHT(F,6))
in column I, expressing total elapsed time in total hours using the traditional time format, an alternate formula is:
=IF(E<1,F,INT(E)*24+HOUR(F)&":"&RIGHT("00"&MINUTE(F),2)&":"&RIGHT("00"&SECOND(F ),2))
Of course the user would choose the format used in column G or the one in column I for his table. There is no need to keep all of them. It would be fine to hide column F whose contents are auxiliary.
Second problem: individual durations may be greater than 23:59:59 hours.
Again, column B is used to store starting date-time, column C stores ending date-time, and durations are calculated in column D. Since B and C are storing full date-time values, we may use this simple formula to find the duration:
=C-B
in column E, the time portion of the duration given in time format is:
=TIME(0,0,ROUND(MOD(D,1) 24*6060,0))
in column F the formula to show the duration as days/hours/minutes is:
=IF(D<1,"",INT(D)&IF(D<2," day "," day(s "))&E
in column G we give the elapsed time in total hours using a time format. The formula is:
=IF(D<1,E,INT(D)*24+LEFT(E,LEN(E)-6)&RIGHT(E,6))
in column H we give the elapsed time in total hours using a time format. An alternate formula is:
=IF(D<1,E,INT(D)*24+HOUR(E)&":"&RIGHT("00"&MINUTE(E),2)&":"&RIGHT("00"&SECOND(E ),2))
If the duration is greater than 24 hours, the results in columns E and F are not a time value but a string. So the value in column D (which is time duration only) is useful.
-+-+-+-+-
*PROBLEM WITH ENTERING TIME*
When you wish to enter 12:34 but 12 is the number of minutes, remember that Numbers will decipher this as 12 hours and 34 minutes. Simple tip:
Assuming that your original entry is in column B, then in column C use this formula to align the minutes and seconds for proper Numbers interpretation:
=IF(ISERROR(TIME(0,LEFT(B,SEARCH(":",B)-1),RIGHT(B,LEN(B)-SEARCH(":",B)))),"",T IME(0,LEFT(B,SEARCH(":",B)-1),RIGHT(B,LEN(B)-SEARCH(":",B))))
-+-+-+-
*MISCELLANEOUS NOTES*
• Of course, the addition of two dates and multiplication or a division applied to one date means nothing and would generate the red triangle announcing a syntax error.
• We may add a time value to a date-time: If B contains a date-time and C contains a time, the following formula will return the sum of the two values:
=B+TIMEVALUE(C)
• We may strip the time value of a full date-time one with the formula: =DATE(YEAR(B),MONTH(B),DAY(B))
• Just as a reminder,
=EDATE(B, 3) adds 3 months to the pure date stored in B
so, of course,
=EDATE(B, 12) adds one year to the pure date stored in B
• If B and C store date-time values,
=C-B returns the difference in decimal days.
=DATEDIF(B,C,"D") returns the number of days between the two pure dates. It's identical to =DATE(YEAR(C),MONTH(C),DAY(C))-DATE(YEAR(B),MONTH(B),DAY(B))
=DATEDIF(B,C,"M") returns the number of months between the two pure dates.
=DATEDIF(B,C,"Y") returns the number of years between the two pure dates.
Three other variants are available which use the parameters "MD","YM" and "YD".
Yvan KOENIG (from FRANCE lundi 25 août 2008 15:23:34)
To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !, Mac OS X (10.4.11)
