4

Given a table that has a column of time ranges e.g.:

|  <2015-10-02>--<2015-10-24> |
|  <2015-10-05>--<2015-10-20> |
....

how can I create a column showing the results of org-evalute-time-range?

If I attempt something like: #+TBLFM: $2='(org-evaluate-time-range $1)

the 2nd column is populated with

 Time difference inserted

in every row.

It would also be nice to generate the same result from two different columns with, say, start date and end date instead of creating one column of time ranges out of those two.

Metropolis
  • 2,018
  • 1
  • 19
  • 36

1 Answers1

11

If you have your date range split into 2 columns, a simple subtraction works and returns number of days:

| <2015-10-05>       | <2015-10-20> |        15 |
| <2013-10-02 08:30> | <2015-10-24> | 751.64583 |
#+TBLFM: $3=$2-$1

Using org-evaluate-time-range is also possible, and you get a nice formatted output:

| <2015-10-02>--<2015-10-24>           | 22 days                    |
| <2015-10-05>--<2015-10-20>           | 15 days                    |
| <2015-10-22 Thu 21:08>--<2015-08-01> | 82 days 21 hours 8 minutes |
#+TBLFM: $2='(org-evaluate-time-range)

Note that the only optional argument that org-evaluate-time-range accepts is a flag to indicate insertion of the result in the current buffer, which you don't want.

Now, how does this function (without arguments) get the correct time range when evaluated is a complete mystery to me; pure magic(!)

Juancho
  • 7,207
  • 27
  • 31
  • That is magic. Thanks! I don't know why I didn't try just subtracting. Good to know that works as well. Nice answer. – Metropolis Oct 23 '15 at 02:38
  • 1
    The "magic" in this case appears to be that `org-evaluate-time-range` will find any timestamp range in the same line, and during formula evaluation point is in the cell whose formula is being calculated. – Aaron Harris Oct 23 '15 at 04:43