| Barry MacDonnell's
Toolbox for WordPerfect
Macros, tips, and
templates for Corel® WordPerfect® for Windows®
| Page updated Jul 7, 2018
Main tips page | Browse tips
|Need to calculate a new date from today's date, or from some other date? Here a several methods.||
There are several ways to do this, depending on what you want as output.• You can use a WordPerfect table to calculate the new date:
Assuming the first date should be in table cell A1 ...
 Format cell A1 as a Date by right-clicking the cell, choosing Numeric Format, then Date/Time. (You can click Custom to format the date differently, if desired.)
 Click OK. In the table cell, enter a date such as 12/4/18 and when you tab to the next cell or click in another cell, the date will appear as a date-formatted string.
Now, assuming you want to calculate a date 90 days hence:
 In the second ("new date") cell, format it as a Date, and then enter this formula in the cell:
The table must be set to auto-calculate:
With the cursor in the table, click the top menu: Table, Calculate. You should see the Calculate dialog, which lets you turn automatic calculation on and off.
Also, make sure you have not turned calculation off in the cell itself (right-click the cell, then choose Format, then un-check the "Ignore cell when calculating" box).
• You can use a WordPerfect floating cell to calculate the new date and insert it at the cursor location.
See Footnote 1 below for the manual procedure and also some macros that can create the floating cell with the formula already in it, and then insert it in your document -- all in one operation.
• You can use a WordPerfect macro from this site to calculate (and optionally insert) a new date that is "x" days in the future (or the past) from today (or other date).
See this small downloadable macro in InsDate.zip. It asks you for a date (the current date is the default), the number of days (plus or minus) from today, and some basic format options for the date. Then it displays the new date in a small dialog, which lets you insert the new date in the document at the current cursor location.
• To find the number of days between two dates,
• To find the day of the week a given date will fall on, try the Find day of week macro.
Roy "lemoto" Lewis has posted several macros that calculate dates, such as Days After and Due Date.
Note section ▸
Here is the manual procedure to create a date-calculating floating table cell (mentioned above):
Here are a few small macros you can copy into your WordPerfect program.
Example #1 - Use the current date, calculate a new date (+/-) "x" days from that date, based on a number of days the user inputs into a small dialog.
Example #2 - Use a static date other than the current date, calculate a new date (+/-) "x" days from that date, based on a number of days the user inputs into a small dialog.
Example #3 - Use the current date, calculate a new date that is a specified number of days from that date.
Example #4 - Use the current date, calculate a new date that is a specified number of days from that date.
Unlike the macros in Footnote 1 above, which use floating table cells, this macro calculates the difference between a target date and the current date using a pair of PerfectScript DateAndTime commands.
Just change (and save) the three Target date variables (vTD, vTM, vTY) to suit your own needs and then play the macro.
The three Current date variables (vCD,vCM,vCY) in this example are taken from WordPerfect system variables (but could just as well be typed into the command instead, similar to the way it was done with the Target date).
To copy this macro code into your WordPerfect program to produce a functioning macro see here.
// Macro code begins:
// Set the Target (future) day, month, year:
vTD:=6 // (target day, 1-31)
vTM:=7 // (target month, 1-12)
vTY:=2021 // (target year, YYYY)
// Set the Current day, month, year (here, via WP system variables):
// Validate the Target date (optional but typically helpful):
vDays:=DateDaysInMonth (Month: vTM; Year: vTY)
If(vTD<1 OR vTD>vDays)
"The Target DAY was set to an invalid day for the Target month: "+vTD)
If(vTM<1 or vTM>12)
"The Target MONTH was set to an invalid number: "+vTM)
If(vTY<1601 or vTY>4000)
"The Target YEAR was set to an invalid number: "+vTY)
// Compute the difference, convert to and integer, and display the result:
MessageBox(;"Difference between the target date and today:"; vDiff+" days.")
// Optional: Do something with the difference; e.g., display a message:
If(vDiff <= 0)
Messagebox(;;"The Target Date has passed.")
Messagebox(;"" ;"The Target Date has NOT passed.")
// ... continue with macro ... (e.g., use Go() to jump to a Label() ) ...
// End of macro