Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate

Barry MacDonnell's
Toolbox for WordPerfect

Macros, tips, and templates for Corel® WordPerfect® for Windows®
© Copyright 1996-2024 by Barry MacDonnell. All Rights Reserved.

Page updated Aug 18, 2024

"Date Inserter" - Displays a dialog to input and convert a chosen date to one of several date formats, including legal-style (ordinal) dates, then type (insert) it into the current document at the cursor location.

Options include automatically adding or subtracting "n" days to the chosen date, and/or just displaying the converted date rather than inserting it.

[Update August 2024: Additional example code snippets are described below to help automate the quick insertion of "legal-style" dates at the cursor location.]

Download DateIns.zip (v1.05; 07/17/2024; 14,205 bytes)

Compatible with WordPerfect X6 and later versions but should work in earlier versions back to WP8

Downloading, Documentation, Modifications, and Support

Purpose

Date Inserter.wcm (v1.05, updated Aug. 17, 2024) is a macro that displays a dialog on screen
with a date field that lets you pick a desired date from a drop-down calendar (or simply type the desired date in a menu field).

It then inserts that date at the current cursor location with the click of a push button, in any of several different formats.

Examples of the date formats -

        August 17, 2024  [standard US version]

        Saturday, August 17, 2024  [day of week plus standard date]

        the 17th day of August, 2024  [ordinal date in numerals+suffix]

        the seventeenth day of August, 2024  [ordinal date in words]

        8/17/2024  [numerical with separators]

        [Tip: Several formats can be modified. See Notes below.]

Other options let you -

        add (or subtract) "n" days to the desired date before inserting it

        display the date on screen only

        add bold formatting to the date

Note that the inserted date is a "static" date -- i.e., it will not automatically change when the document is saved and opened at a later time.

For automatic date/time changes you can manually use WordPerfect's menu: Insert, Date/Time, <choose a date/time format>, enable the checkbox "Keep the inserted date current," and click Insert. That feature inserts a dynamic date (via a format code) that changes when the current date changes. Dynamic dates can be useful to "stamp" a document with the then-current print date and time, revision date, etc.

Minor limitation

The current version of this macro gets the current user's date format from Windows (stored in the Windows Settings: search Settings for "Region"). It assumes the "short" date is displayed in the format of M/d/yyyy -- e.g., 8/17/2024 (August 17, 2024), as used in the English (United States) format. It will not work without modification to accommodate other date formats. [Hopefully this will be fixed in the future, although the macro language presents certain difficulties when using a calendar tool in a dialog, such as used in Date Inserter.wcm.]

Instructions

First, extract the Date Inserter.wcm macro from inside the downloadable ZIP file. [See "Downloading..." instructions if you need help with this.]

1. Simply place the cursor where you want the date inserted in the document and then play the macro. A dialog appears.

2. Choose the desired date by typing it into the top-left date field or by using the drop-down calendar tool. Note that manually typed dates into the date field are not checked for validity (just follow the format shown in the field). However, the calendar tool will always produce a valid date.

3. Choose from the other options. [One is a checkbox that lets you display the date on screen in a message box dialog instead of inserting it; press OK to dismiss the  message and end the macro.]

4. Press the appropriate date format push-button on the right side of the dialog. This inserts the chosen date in the document and ends the macro.

Notes

• You can edit the Date Inserter macro like any other WordPerfect document. The best way is to use the WordPerfect menu: Tools > Macro > Edit.

•  The Date Inserter macro has several menu items which can be set to other defaults in the redlined User Modification Area at the top of the macro's code.

•  Dates in the Date Inserter macro's code (and the alternative plain-text macro code below) follow the Month-Day-Year format. To change date formats and/or the order of date components that are inserted by several of the push buttons on the macro's main menu, see the comments at the top of the macro's code.

Additional code snippets for experienced macro users

Here are two example snippets of macro code that can be used (and modified if required) in other macros (or as standalone macros) to
 
[1] type the current (system) date into a document
[2] as a static date (see above - and also "Limitations")
[3] in "legal" format
[4] using ordinal numbers.

Notes

¤  The first example snippet uses numerals in the ordinals (1st, 2nd, 3rd ... 31st.).
For example, "the 17th day of August, 2024".


¤  The second example snippet below spells out the ordinals.
For example, "
the seventeenth day of August, 2024
".

¤  Both snippets can be used inside substructures such as Headers, Footers, Footnotes, Endnotes, Tables, and Text Boxes.

¤  You can modify the Type() commands to add or delete words, spaces, or punctuation marks. Just be sure these items are enclosed in pairs of double quote marks, as shown in the examples.

¤  To copy such plain-text code into your WordPerfect program to create a working macro see https://wptoolbox.com/tips/CopyCode.html.

Example #1

// Macro snippet begins:

// - - - - -
// (Insert optional code here to position the
// cursor where desired; if omitted, the date
// is inserted at the current cursor location.)
// - - - - -

// First, get the 3 date components from
// the user's system; the StrTrim() command
// removes any leading zero in
the system
// variable ?DateDay -
vDay:=StrTrim (?DateDay;;TrimLeft!;"0")
vMonth:=?DateMonth
vYear:=?DateYear

// Then insert the date in "legal" format at
// the cursor position -
Type ("the "+fAbbrevDay(vDay)+
" of "+fMonthName(vMonth)+", "+vYear)

// Exit here -
Return

// = = = =  = = = = = =

// The two Functions below return the current month
// and day for use in the Type() command above.
// (Original functions were coded by John Land.)

Function fMonthName (vInStr) //(get current month)
  vMonthList[]=
    {
"January";"February";"March";"April";"May";
    "June";"July";"August";
"September";
    "October";"November";"December"}
  Return (vMonthList[vInStr])

EndFunc

Function fAbbrevDay (vInDay) //(convert day->ordinal)
  Switch (vInDay)
     CaseOf "01";"1";"21";"31": vOutDay=vInDay+"st"
     CaseOf "02";"2";"22": vOutDay=vInDay+"nd"
     CaseOf "03";"3";"23": vOutDay=vInDay+"rd"
     Default: vOutDay=vInDay+"th"
  EndSwitch
  Return (vOutDay)  // returns day as ordinal (e.g., "31st")
EndFunc

// Macro snippet ends

Example #2

This example snippet is the same as Example #1 -- but spells out the ordinals.
For example, "the seventeenth day of August, 2024".

// Macro snippet begins:

// - - - - -
// (Insert optional code here to position the
// cursor where desired; if omitted, the date
// is inserted at the current cursor location.)

// - - - - -


// First, get the 3 date components from
// the user's system; the StrTrim() command
// removes any leading zero in
the system
// variable ?DateDay -

vDay:=StrTrim (?DateDay;;TrimLeft!;"0")
vMonth:=?DateMonth
vYear:=?DateYear

// Then insert the date in "legal" format at
// the cursor position -
Type ("the "+fAbbrevDay(vDay)+
" of "+fMonthName(vMonth)+", "+vYear)

// Exit here -
Return

// = = = = = = = = = =

// The two Functions below return the current month
// and day for use in the Type() command above.

Function fMonthName (vInStr)
//(get current month)
  vMonthList[]=
     {"January";"February";"March";"April";"May";
     "June";"July";"August";"September";
     "October";"November";"December"}

  Return (vMonthList[vInStr])
EndFunc

Function fAbbrevDay (vInDay)
//(convert day->ordinal)
  Switch (vInDay)
    CaseOf "01";"1": vOutDay="first"
    CaseOf "02";"2": vOutDay="second"
    CaseOf "03";"3": vOutDay="third"
    CaseOf "04";"4": vOutDay="fourth"
    CaseOf "05";"5": vOutDay="fifth"
    CaseOf "06";"6": vOutDay="sixth"
    CaseOf "07";"7": vOutDay="seventh"
    CaseOf "08";"8": vOutDay="eighth"
    CaseOf "09";"9": vOutDay="ninth"
    CaseOf "10": vOutDay="tenth"
    CaseOf "11": vOutDay="eleventh"
    CaseOf "12": vOutDay="twelfth"
    CaseOf "13": vOutDay="thirteenth"
    CaseOf "14": vOutDay="fourteenth"
    CaseOf "15": vOutDay="fifteenth"
    CaseOf "16": vOutDay="sixteenth"
    CaseOf "17": vOutDay="seventeenth"
    CaseOf "18": vOutDay="eighteenth"
    CaseOf "19": vOutDay="nineteenth"
    CaseOf "20": vOutDay="twentieth"
    CaseOf "21": vOutDay="twenty-first"
    CaseOf "22": vOutDay="twenty-second"
    CaseOf "23": vOutDay="twenty-third"
    CaseOf "24": vOutDay="twenty-fourth"
    CaseOf "25": vOutDay="twenty-fifth"
    CaseOf "26": vOutDay="twenty-sixth"
    CaseOf "27": vOutDay="twenty-seventh"
    CaseOf "28": vOutDay="twenty-eighth"
    CaseOf "29": vOutDay="twenty-ninth"
    CaseOf "30": vOutDay="thirtieth"
    CaseOf "31": vOutDay="thirty-first"
  EndSwitch
  Return (vOutDay) // returns day in ordinal format
EndFunc

// Macro snippet ends