ok, this one just does hours, mins and secs, by converting to seconds, then working back. simple. (and can probably be made smaller..)
the thing that stumped me was the answer you first gave for 33:52 is (i think) wrong. 085156 is 000804 away from 090000, and so
000804 + 002448 => 24+8 : 04+48 => 32:52. (an hour head scratching for that one..)
the year:month:day part will need leapyears (divisible by 400 and 4) and the months(28,30,31). and im not doing that just yet..
(defun C:testdatediff ()
(datediff "20061103.085156" "20061103.092448" )
(datediff "20061103.080156" "20061103.205448" )
(datediff "20061103.080156" "20061103.080200" )
(datediff "20061103.080156" "20061103.090156" )
(datediff "20061103.085530" "20061103.095520" )
(datediff "20061103.000000" "20061103.235959" )
(princ)
)
(defun datediff ( DATEA DATEB / HMSA HMSB HMSD HOURD MIND SECD )
(setq HMSA (+ (* 3600 (read(substr DATEA 10 2)))
(* 60 (read(substr DATEA 12 2)))
(* 1 (read(substr DATEA 14 2))) )
HMSB (+ (* 3600 (read(substr DATEB 10 2)))
(* 60 (read(substr DATEB 12 2)))
(* 1 (read(substr DATEB 14 2))) )
HMSD (abs(- HMSA HMSB))
HOURD (/ HMSD 3600)
MIND (/ (- HMSD (* HOURD 3600)) 60)
SECD (- HMSD (* HOURD 3600) (* MIND 60))
)
(princ "\nHOUR:MIN:SEC Difference between " )(princ DATEA)(princ " and ")(princ DATEB)(princ " is ")
(princ (strcat (itoa HOURD) ":" (itoa MIND) ":" (itoa SECD) ))
(princ)
)