I wish to calculate time string delta as below:

| date       | delta |
| 2018/12/28 |     0 |
| 2018/12/31 |    -1 |
#+TBLFM: $2=if(2==@#, 0, ($1 - @-1$1); %.0f

The expected answer should be 3 but now it's -1. I do not wish to change the time string format in table.

How can I modify the formula to covert timestring to datetime correctly?


Although you said you do not want to change the date format that is what you have to do to use the $1 syntax in the formula. For that to work, org mode functions will need to know that you are dealing with dates.

The first prerequisite is the brackets around the dates. Secondly, I had to go to full ISO format date for org to recognize the date. That might depend on my settings.

| date         | delta |
| [2018-12-28] |     0 |
| [2018-12-31] |     3 |
#+TBLFM: $2=if(2==@#, 0, ($1 - @-1$1); %.0f

The alternative is to put together a very long formula using custom elisp to do the same thing.

  • The date field can be an active date <YYYY-MM-DD> or an inactive date [YYYY-MM-DD] but indeed it cannot be a bare date as the OP wants it: org mode will not recognize it. It also has to be an ISO date: org mode can be customized to output dates in other formats (generally as an overlay of some sort) but it only understands ISO dates on input. – NickD Dec 30 '18 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.