Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate time range in org-mode table

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.

like image 963
Metropolis Avatar asked Dec 25 '22 13:12

Metropolis


1 Answers

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(!)

like image 132
Juancho Avatar answered Dec 27 '22 09:12

Juancho