Question

If an org table cell contains the HMS 1@ 11' 37"

is there an easy way to get the total (time)seconds?

(1*3600 + 11*60 + 37 = 4297)

Was it helpful?

Solution

Try this:

(defun hms-to-seconds (str)
  (let* ((lst (split-string str "@ "))
     (hour (car lst))
     (lst2 (split-string (cadr lst) "' "))
     (minute (car lst2))
     (second (car (split-string (cadr lst2) "\""))))
    (+ (* (string-to-number hour) 3600)
       (* (string-to-number minute) 60)
       (string-to-number second))))

Upd: As @Juancho noted there is more simple way with direct hms calculations:

| 1@ 11' 37" | 4297 | 4297 |
#+TBLFM: $2='(fmt-to-seconds $1)::$3=$1\ 0@ 0' 1"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top