This procedure will return a variable length text string representing a date. For example:
String = Datetext(D'2010-01-01'); // Returns 'January 1, 2010' String = Datetext(); // Returns formatted system date String = Datetext(Mydate); // Returns formatted date in Mydate
Here is the procedure code:
// ------------------------------------------------------------------ // // Procedure Datetext: Returns a date formatted as text // // Examples: String = Datetext(D'2010-01-01'); // 'January 1, 2010' // String = Datetext(); // Returns formatted system date // // ------------------------------------------------------------------ H Nomain D Datetext PR 18 Varying D D Value D Options(*Nopass) D Datfmt(*Iso) P Datetext B Export D PI 18 Varying D Indate D Value D Options(*Nopass) D Datfmt(*Iso) D Today S D Inz(*Sys) D Monthsdata DS D 9 Inz('January') D 9 Inz('February') D 9 Inz('March') D 9 Inz('April') D 9 Inz('May') D 9 Inz('June') D 9 Inz('July') D 9 Inz('August') D 9 Inz('September') D 9 Inz('October') D 9 Inz('November') D 9 Inz('December') D Months 9 Overlay(Monthsdata) D Dim(12) /Free If %Parms > 0; Today = Indate; Endif; Return %Trim(Months(%Subdt(Today:*M))) + ' ' + %Char(%Subdt(Today:*D)) + ', ' + %Char(%Subdt(Today:*Y)); /End-free P E