I personally use my function "dtocfmt( <date>, <cformat> )", whenever I need to show date in a non-conventional format or a format different than the Set Date format.
In a case like this I would
bStrDate := { || dtocfmt( <datevar>, 'dd-mm-yyyy' ) }
Here is the source code of the function:
- Code: Select all Expand view RUN
function dtocfmt( dDate, cFormat )
local cDate
DEFAULT cFormat := Set( _SET_DATEFORMAT )
cDate := Lower( cFormat )
cDate := StrTran( cDate, 'dd', StrZero( Day( dDate ), 2 ) )
if 'mmmm' $ cDate
cDate := StrTran( cDate, 'mmmm', cMonth( dDate ) )
elseif 'mmm' $ cDate
cDate := StrTran( cDate, 'mmm', Left( cMonth( dDate ), 3 ) )
else
cDate := StrTran( cDate, 'mm', StrZero( Month( dDate ), 2 ) )
endif
if 'yyyy' $ cDate
cDate := StrTran( cDate, 'yyyy', Str( Year( dDate ), 4, 0 ) )
else
cDate := StrTran( cDate, 'yy', StrZero( Year( dDate ) % 100, 2 ) )
endif
return cDate
Format is case insenstive and date, month and year can be positioned anywhere.
Example formats and results:
dd-mm-yy ->22-07-08
dd-mmm-yyyy -> 22-Oct-2008
mmmm dd, yyyy -> October 02, 2008
mmm yyyy -> OCT 2008