k, heres the YEAR.MONTH.DAY part. same as before, but now we convert to DAYS, and no need to convert back. (representing a DIFFERENCE as a DATE would be misleading..)
maybe tommorow ill make the whole day+seconds thing work..
not sure anymore if its what you were asking for, but its something i put off for a while, and needed, a logging of drawings opened/closed by the various drafters here. a pleasant hour of afternoon coding before an earlymark, before the great ozzie horse race==melbourne cup, around the same time that the yanks have their great race.. (both can be interpreted as to be dealing with issues of cruelty to animals..
)
; ----------------------------------------------------------------------------
; memeeng 071106
;
(defun C:testdatediff ()
(datediff "20061101.000000" "20061102.111111" )
(datediff "20061001.000000" "20061101.111111" )
(datediff "20051001.000000" "20061001.111111" )
(datediff "20000101.000000" "20010101.111111" )
(datediff "20010101.000000" "20020101.111111" )
(princ)
)
; ----------------------------------------------------------------------------
; memeeng 071106
;
(defun datediff ( DATEA DATEB / DAYEA DAYEB DAYEC)
(setq DAYEA (CountDaysUntil DATEA)
DAYEB (CountDaysUntil DATEB)
DAYEC (if (< DAYEA DAYEB) (- DAYEB DAYEA) (- DAYEA DAYEB) )
)
(princ "\nDAY Difference between " )(princ DATEA)(princ " and ")(princ DATEB)(princ " is ")
(princ DAYEC)(princ " days.")
)
; ----------------------------------------------------------------------------
; memeeng 071106 RETURNS total days up till YEAR
;
(defun CountYearDaysUntil ( YEAR / YEARC DAYEC )
(setq YEARC 0
DAYEC 0)
(while (< YEARC YEAR)
(setq DAYEC (+ DAYEC (if(or(= 0 (rem YEARC 4))(= 0 (rem YEARC 400))) 366 365) ))
(setq YEARC (1+ YEARC))
)
DAYEC
)
; ----------------------------------------------------------------------------
; memeeng 071106 RETURNS total days up to MONTH
;
(defun CountMonthDaysUntil( YEAR MUNF / MUNFC DAYEC )
(setq DAYEC 0 MUNFC 1)
(while (< MUNFC MUNF)
(setq DAYEC (+ DAYEC (nth (1- MUNFC) (list 31 28 31 30 31 30 31 31 30 31 30 31)) )
MUNFC (1+ MUNFC))
);endWHILE
(if (and(> MUNF 2)(or(= 0 (rem YEAR 4))(= 0 (rem YEAR 400))) )
(1+ DAYEC)
DAYEC
);FeburayFIX
)
; ----------------------------------------------------------------------------
; memeeng 071106 RETURNS date as TOTAL DAYS since YEAR 0.1.1
;
(defun CountDaysUntil ( DATE )
(+ (CountYearDaysUntil (read(substr DATE 1 4)) )
(CountMonthDaysUntil (read(substr DATE 1 4)) (read(substr DATE 5 2)) )
(read(substr DATE 7 2)) )
)