Purpose
Returns a date formatted in the short date style. You can call this function from the MapBasic window in MapInfo Pro.
Syntax
FormatDate$( "date", "dateFormat", "locale" )
date is a number or string representing the date in a YYYYMMDD format, where YYYY is the year, MM is the month between 01 (January) and 12 (December), and DD is the day of the month between 01 and 31.
dateFormat is an optional string expression representing the date format to apply (overriding the system date format ).
locale is an optional string expression representing the locale of the date format applied.
Return Value
String
Description
The FormatDate$() function returns a string representing a date in the local system format as specified by the Control Panel.
If you specify the year as a two-digit number (for example, 96), MapInfo Pro uses the current century or the century as determined by the Set Date Window() statement.
Year can take two-digit year expressions. Use the Date window to determine which century should be used. See DateWindow() function.
You can also use the optional dateFormat and locale arguments to explicitly apply date formatting conventions.
Examples
This example uses the optional dateFormat and locale arguments to explicitly apply date formatting conventions.dim dt as date
dt = StringToDate("3/21/2021")
print FormatDate$(dt, "dd MMMM yyyy", "de-DE")
‘returns : 21 März 2021
print FormatDate$(dt, "D")
‘returns: Sunday, March 21, 2021
print FormatDate$(dt, "MM/dd")
‘returns: 03/21
This examples assumes that the Control Panel settings are Day/Month/Year for date order, '-' for date separator, and "dd-MMM-yyyy" for short date format:
Dim d_Today As Date
d_Today = CurDate()
Print d_Today 'returns "19970910"
Print FormatDate$( d_Today ) 'returns "10-Sep-1997"
Dim s_EnteredDate As String
s_EnteredDate = "03-02-61"
Print FormatDate$( s_EnteredDate ) 'returns "03-Feb-1961"
s_EnteredDate = "12-31-61"
Print FormatDate$( s_EnteredDate ) ' returns ERROR: not d/m/y ordering
s_EnteredDate = "31-12-61"
Print FormatDate$( s_EnteredDate ) ' returns 31-Dec-1961"
See Also:
Date and Time Functions, FormatTime$() function, DateWindow() function, Set Date Window() statement