Author Topic: Deduct Dates in Autolisp  (Read 2285 times)

0 Members and 1 Guest are viewing this topic.

@_Bilal

  • Mosquito
  • Posts: 19
Deduct Dates in Autolisp
« on: January 19, 2019, 07:35:15 AM »
Hi Guys,

Is there an AutoLISP routine to deduct two dates and get the results in days
for example: last date is  "19750225"  year 1975 month 02 day 25 and the current date is (rtos (getvar "cdate") 2 0)
The question is how to get the exact days between this 2 dates in autolisp.

Thanks

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Deduct Dates in Autolisp
« Reply #1 on: January 19, 2019, 08:01:51 AM »
Convert the dates to Julian then subtract, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun daydiff ( d1 d2 )
  2.     (- (fix (dtoj d2)) (fix (dtoj d1)))
  3. )
Code - Auto/Visual Lisp: [Select]
  1. _$ (daydiff 20190117 (getvar 'cdate))
  2. 2
  3. _$ (daydiff 20181219 (getvar 'cdate))
  4. 31

(dtoj is part of Julian.lsp included with Express Tools)

Note that the DATE system variable returns a Julian date already, so if you simply want the difference from the current date, the code may be:
Code - Auto/Visual Lisp: [Select]
  1. (defun daydiffnow ( d1 )
  2.     (- (fix (getvar 'date)) (fix (dtoj d1)))
  3. )
Code - Auto/Visual Lisp: [Select]
  1. _$ (daydiffnow 20190117)
  2. 2
« Last Edit: January 19, 2019, 08:10:03 AM by Lee Mac »

@_Bilal

  • Mosquito
  • Posts: 19
Re: Deduct Dates in Autolisp
« Reply #2 on: January 19, 2019, 08:22:46 AM »
Thank you Lee Mac.