Author Topic: add / subtract dates  (Read 1092 times)

0 Members and 1 Guest are viewing this topic.

AMAM

  • Mosquito
  • Posts: 5
add / subtract dates
« on: April 21, 2020, 06:08:18 AM »
Is there is any way of adding for example 30 minutes to the result of "(rtos (getvar 'cdate) 2 6)" also the reverse,
keep in mind in special occasions that might result in jumping to the next day, month or year.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: add / subtract dates
« Reply #1 on: April 21, 2020, 08:33:30 AM »
I would suggest using the value returned by DATE rather than CDATE.

DATE stores the current date & time as a Julian date value, with the value following the decimal point representing the fraction of a day. Hence, to add 30 minutes you simply need to divide 30 by the number of minutes in a day (1440) and add this to the value returned by the DATE system variable.

The result can then be represented in a human readable format using the DIESEL edtime function, evaluated from a menu command expression, e.g.:

Code - Auto/Visual Lisp: [Select]
  1. (menucmd "m=$(edtime,$(+,$(getvar,date),$(/,30.0,1440.0)),yyyy-mo-dd hh:mm:ss)")

AMAM

  • Mosquito
  • Posts: 5
Re: add / subtract dates
« Reply #2 on: April 21, 2020, 11:04:49 AM »
THANK YOU ALOT SIR,
For easy solution and the explanation I'm really grateful.