How to calculate a date

Get help using and writing Nisus Writer Pro macros.
Post Reply
vwnisus
Posts: 31
Joined: 2016-04-24 00:13:31

How to calculate a date

Post by vwnisus » 2019-02-03 11:49:00

I would like to know whether it is possible to have a macro where I am able to add (or go back)1 day to today's date.

I understand to get today's date:

Code: Select all

$today = date.now
so $today = date. now + 1 day

Is there a(n easy) way to do this in Nisus Writer Pro?

User avatar
phspaelti
Posts: 1015
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to calculate a date

Post by phspaelti » 2019-02-03 15:45:34

As far as I know, Nisus Macro language is still case sensitive, so you'll need to write:

Code: Select all

$today = Date.now
To get the next day you have basically two methods, simpler:

Code: Select all

$nextDay = $today.dateByAddingSeconds 86400
…and fancier:

Code: Select all

$y = $today.year
$m = $today.month
$d = $today.day + 1
$nextDay = Date.newWithYearMonthDay $y, $m, $d
The latter method can be combined into 1 line, like so:

Code: Select all

$nextDay = Date.newWithYearMonthDay $today.year, $today.month, ($today.day + 1)
philip

Post Reply