What you wanted to know about Time values

Hello

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)

Posted on Aug 25, 2008 6:24 AM

Reply
14 replies

Aug 26, 2008 6:00 AM in response to KOENIG Yvan

I add some enhanced formulas given in a longer version in an other thread.

User uploaded file

in column C, the formula calculating age is:
=IF(ISBLANK(B),"",DATEDIF(B,TODAY(),"Y"))
in column D, the formula calculating the anniversary in the current year is:
=IF(ISBLANK(B),"",DATE(YEAR(TODAY()),MONTH(B),DAY(B)))
in column E, the formula calculating the next anniversary is:
=IF(ISBLANK(B),"",DATE(IF(DATE(YEAR(TODAY()),MONTH(B),DAY(B))<TODAY(),1,0)+YEAR( TODAY()),MONTH(B),DAY(B)))

Yvan KOENIG (from FRANCE mardi 26 août 2008 14:50:19)

Aug 26, 2008 10:29 AM in response to KOENIG Yvan

If we want the age given in years and days, we may use the formula:

=IF(ISBLANK(B),"",DATEDIF(B,TODAY(),"Y")&" years "&IF(DATE(YEAR(TODAY()),MONTH(B),DAY(B))=TODAY(),"",DATEDIF(DATE(IF(DATE(YEAR(T ODAY()),MONTH(B),DAY(B))<TODAY(),0,-1)+YEAR(TODAY()),MONTH(B),DAY(B)),TODAY(),"d ")&" day(s)"))

If you need other formulas, you may ask for them.

Yvan KOENIG (from FRANCE mardi 26 août 2008 19:28:22)

Aug 28, 2008 6:00 AM in response to KOENIG Yvan

there is a feature of the DATE() function which is not described:

=DATE(0,1,1) which is meaningless ( _there is no year zero_ ) returns 01/01/0001 which is and odd value but matches what most beings think when they speak of year zero.

there is a limitation of the DATE() function which is not described:

=DATE(-10,1,1) returns an error. It doesn't accept a negative year. Nothing existed before 01/01/0001 !

there is a feature of the TIME() function which is not described:
the time value can't be negative.

=TIME(1,-5,-6) is correct
=TIME(1,5,-70) is correct
but
=TIME(0,0,-1) is wrong
=TIME(0,-1,0) is wrong
=TIME(-1,0,0) is wrong

Yvan KOENIG (from FRANCE jeudi 28 août 2008 14:57:36)

Aug 29, 2008 3:19 AM in response to KOENIG Yvan

KOENIG Yvan wrote in his "*STORED DATE-TIME VALUES - BASICS*" section:

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.


This is not exactly true. Numbers files store date-time values in a string format consistent with ISO 8601:2004. This format explicitly includes year, month, day, hour, minute, & second values.

This may be verified by examining the uncompressed index.xml file in a Numbers package. For example, the first day of 1904 is stored as cell-date="1904-01-01T00:00:00+0000" & of the year 0001 as cell-date="0001-01-01T00:00:00+0000." This format is not a numeric value of seconds from a base date-time, often referred to as a "serial time" format, that is used in applications like AppleWorks (or Excel?).

Note that the time value (all that follows the "T" in the string) actually has four components, the last one (following the plus) representing the time zone offset from UTC time in minutes. AFAIK, Numbers does not set this to anything besides "+0000" but interestingly, it will attempt to interpret it if set by manually editing the file. For example, change cell-date="1904-01-01T00:00:00+0000" to cell-date="1904-01-01T00:00:00+0120" & the cell will display the last day of December of 1903 as the date, but will still show the time as 00:00:00. This suggests a future version of Numbers might be time zone aware, but currently it is unreliable & not fully implemented.

Anyway, Numbers does not use the first day of 1904 as a reference for stored date-time values, although it will add that date to "dateless" time values imported from AppleWorks spreadsheets. Although I have not verified this, I believe it will also seamlessly translate between ISO & serial time formats as needed for Excel imports & exports, using the first day of 1900 as needed.

Some other things to note about the ISO standard:

• It permits fractional time values in the smallest time unit present, so for example "T10:15:30" could be represented as "T10:15.5" but Numbers does not support this -- the cell will appear empty if the index file is manually edited this way.

• It does not stipulate whether date-time values represent intervals or durations (although it includes an explicit format for intervals between any two date-time values, known as a period). This means a future version of Numbers could support durations without the addition of a new data storage type, but legacy & import/export issues could make this too impractical to implement.

• It supports a variety of other formats, including date-only, time-only, day-of-year, week-of-year, & various truncations (just hours & minutes, for example). All are unambiguous so a future version of Numbers could support them, but files generated with those versions would not be backwards compatible with the current version.

For completeness, I will add that instead of using complex formulas to manipulate single-cell date-time values in Numbers, it is sometimes more straightforward to use multiple cells, one for each unit of time (for example, days, hours, minutes, & seconds), plus simple arithmetic formulas to combine them. Since each unit is a simple number, this results in highly portable, accurate, & "future-proof" tables, especially for durations. This is particularly useful for multimedia work in which the units might include video or film frames or audio samples.

Oct 8, 2008 12:50 PM in response to KOENIG Yvan

the issue I'm having after following your instructions for elapsed time (duration):

first, the results were listed as times themselves, i.e. instead of saying returning a result of 1 hour, it returned a result of 1:00 AM or 3:15 AM and so on.
second, though I was able to lose the AM distinction by changing the cell format to number instead of date/time, the SUM function does not work when trying to then find out the total duration.

when trying to figure out the total operational time of a particular machine, I have entered start times in column A and end times in column B. using the formula you gave in your post, column C contains the duration, though I have changed the cell format to number so that it doesn't show up with the AM as noted above. so, column C contains three durations: 1:00, 1:30, and 5:00. what formula can I use to show the total of these durations at the bottom of column C (i.e. it should return 7:30 or 7.5 hours)?


*forgive me for posting if a question such as this has already been answered, but I have done a search of the forums and have not found this particular question answered. everyone just refers the asker to your post, which doesn't seem to fully address my issue.

Oct 8, 2008 1:20 PM in response to bshorey

bshorey wrote:
the issue I'm having after following your instructions for elapsed time (duration):
first, the results were listed as times themselves, i.e. instead of saying returning a result of 1 hour, it returned a result of 1:00 AM or 3:15 AM and so on.


There is no duration format so, _it's our duty_ to apply the wanted format: hh:mm:ss

second, though I was able to lose the AM distinction by changing the cell format to number instead of date/time, the SUM function does not work when trying to then find out the total duration.


Changing from date-time to number never changes the behavior of a time value.
We just need to apply the correct time format as I wrote before.

User uploaded file

All the used formulas are given in the thread and in the document available on my idisk (with examples).

in D2 & D3, the used formula is: =TIMEVALUE(C)-TIMEVALUE(B) which returns the durations in decimal days.

in E2 & E3, the used formula is: =TIME(0,0,D 24*6060) which convert the time in decimal days in the common hh:mm;ss format.

in the footer cell D5, the formula is = SUM(D) which adds the values available in the other cells of column D which, here again returns a value in decimal days.

in the footer cell E5, the formula is =TIME(0,0,D5 24*6060) which converts the value stored in D5 in the common hh:mm:ss

I don't repeat the formula able to treat values greater than 23:59:59, it is available in the thread.

If you accept to work with decimal hours, the problem is easier to treat.

in D2 & D3, use the formula : =(TIMEVALUE(C)-TIMEVALUE(B))*24 or perhaps better: =ROUND((TIMEVALUE(C)-TIMEVALUE(B))*24,2) which returns the durations in decimal hours (yes, most of the time, a days contains 14 hours).

given that
in D5 use the formula =SUM(D)

I repeat: all these formulas are available in the existing thread.

Yvan KOENIG (from FRANCE mercredi 8 octobre 2008 22:19:21)

Jan 5, 2009 6:27 AM in response to KOENIG Yvan

Complementary examples.

User uploaded file

Here we build lists of dates.

The table has an header row so I enter the formulas only once, in row 1.

In B1 it is:
IF(ROW()=2,DATE(2009,1,1),DATE(YEAR(INDIRECT(ADDRESS(ROW()-1,COLUMN()))),MONTH(I NDIRECT(ADDRESS(ROW()-1,COLUMN()))),1+DAY(INDIRECT(ADDRESS(ROW()-1,COLUMN())))))
It displays a blue triangle at each beginning of a new month.

In C1 it is:
=IF(ROW()=2,DATE(2009,1,1),DATE(YEAR(INDIRECT(ADDRESS(ROW()-1,COLUMN()))) IF(MOD(ROW()-2,12),0,1),IF(MOD(ROW()-2,12),1MONTH(INDIRECT(ADDRESS(ROW()-1,COLUMN()))),1),DAY(INDIRECT(ADDRESS(ROW()-1,COLUM N())))))
and returns every first day of consecutive months.

In D1 it is:
=IF(ROW()=2,DATE(2009,1,1),DATE(YEAR(INDIRECT(ADDRESS(ROW()-1,COLUMN()))) IF(MOD(ROW()-2,4),0,1),IF(MOD(ROW()-2,4),3MONTH(INDIRECT(ADDRESS(ROW()-1,COLUMN()))),1),DAY(INDIRECT(ADDRESS(ROW()-1,COLUM N())))))
and returns the first day of every consecutive quarters.

Yvan KOENIG (from FRANCE lundi 5 janvier 2009 15:27:12)

Jan 8, 2009 4:06 AM in response to KOENIG Yvan

Salut,

This is really helpful stuff. Looking over it a few times, I don't think it quite answers my dilemma. I create a document in Google Docs and have exports it as an xls.

The document is here: http://www.shampoo.ca/files/PMC_2009.xls

I this document, in column J is Duration. There is no start or end time. I merely took the amount of time I was on the bike and entered this here. Using Google Docs or Excel, I can then SUM up these (L16 for example).

This obviously does not work in Numbers. The times BTW should never go over 24hrs. We can make that assumption.

Any ideas on how to covert this ?

Thanks

Merci!

Jan 10, 2009 10:00 AM in response to Community User

I got your file and don't understand where is the problem.

Between the column Duration (hrs) and the column IF,
insert a new column Duration (deci)

In column Duration (hrs) enter the duration in the hh:mm:ss format
In the column Duration (deci) enter the formula =TIMEVALUE(J)
So you will be able to work with this numerical value.
If you wish you may use the ROUND function.
=ROUND(TIMEVALUE(J),2)

Yvan KOENIG (from FRANCE samedi 10 janvier 2009 19:00:29)

Mar 4, 2009 2:04 PM in response to KOENIG Yvan

I have an agenda of:
Meeting start time
Item duration
... and wish to calculate the start time of the next item on the agenda.

Eg:
Item Time Duration
welcome 9:30 AM 0:05
Overview 9:35 AM 0:15
Minutes 9:50 AM etc

Thanks to Yvan Koenig, I eventually found his simple solution:

"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)"

I found that:

The Time (Cell B) must be displayed in Date Time format. With Date as "none", and Time as your choice, eg: 2:10 PM

The duration (cell C) must be entered in Hours:mins format. The cell format is NUMBER or Text

Mar 6, 2009 6:58 AM in response to myndsurfer

myndsurfer wrote:
I have an agenda of:
Meeting start time
Item duration
... and wish to calculate the start time of the next item on the agenda.

Eg:
Item Time Duration
welcome 9:30 AM 0:05
Overview 9:35 AM 0:15
Minutes 9:50 AM etc

Thanks to Yvan Koenig, I eventually found his simple solution:

"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)"

I found that:

The Time (Cell B) must be displayed in Date Time format. With Date as "none", and Time as your choice, eg: 2:10 PM

The duration (cell C) must be entered in Hours:mins format. The cell format is NUMBER or Text


NO, NO and NO.

Even if you do that, after entering the values today 2009/03/06,

You will see only the time part but your cell will contain
the date_time value 2009/03/06 9:35

How must I write that a date_time cell contains ALWAYS a date and a time !!
The setting date = none just change the display, it doesn't change the contents.

I didn't took time to explain with so much details if the format what behving as you described it.
Is it so difficult to read carefully ?

User uploaded file

Here,
I entered 09:30 in cell B1 on 2009/03/04
I entered 00:05 in cell C1 on 2009/03/04
I entered 09:20 in cell B2 on 2009/03/06
I entered 00:15 in cell C2 on 2009/03/06
in column D the formula is: =B+TIMEVALUE(C)
in column E it is =D
I applyed to column E the format: date = none

In F2, the formula is =E2-E1
and of course, as you are wrong, the result is not zero but 2 (two days).

Changing the format of column C to number or text will change nothing to the behavior.

When we do this kind of thing, the neater soluce is to use date_time for both columns.
This would get rid of odd values like 09:65.
As they would be treated as string because they can't be deciphered as time, they would be display on the left of the cell while correct values are on the right.

Yvan KOENIG (from FRANCE vendredi 6 mars 2009 15:58:36)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

What you wanted to know about Time values

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.