Visual Basic for Applications/Date-Time String Formats

Summary
'''This page lists VBA code to format date-time strings and intervals. It is for use in Microsoft Excel and similar applications that run VBA code. The procedure takes a date variable and returns it as a formatted string. The parameter nOpt sets the chosen format from a set that includes dates, times, or intervals'''. There are two main format types in use:
 * Strings containing a date, are those that display a day, month, and year, with or without times added to them. The important point here is that the number of days stored in the date variable is intended to be displayed as a date, as opposed to an integer. For example, the integer stored for 25 December 2018 is just 43459 and is only converted for display.   Nearly all of the format options in the code module are of this basic type.
 * Strings containing time intervals, are intended to display the number of days as an integer, as opposed to displaying it as a conventional date; that is, in the format d:h:m:s, like a stopwatch.  If a date format is selected for an intended for an interval of a couple of days or so, then a very early date near 1900 will be displayed.   That said, such an error might still be useful for those curious about the actual number of days associated with a particular date.  One time interval format has been included to illustrate the difference in the method, while a full set of these can be found on an adjacent page.
 * Date-time variable assignment examples can be found in the procedure DateAssign.

VBA Code Module
Copy the entire VBA code listing into a standard module, select a formatting option (1-15) in the top procedure, then run it.

Modifications

 * 10 Jan 2019, DateTimeFormat code modified to include one interval format.