HeaderPane
Main
Hide
Share Link
Print

FormatDate Method, SftMaskCalendar Object

Converts a date into a displayable string.

Syntax

C#void object.FormatDate(System.DateTime Dt, ref string Text);
VB.NETobject.FormatDate(ByVal Dt As Date, ByRef Text As String)
C++HRESULT object->FormatDate(DATE Dt, _bstr_t* Text);
CHRESULT object->raw_FormatDate(DATE Dt, BSTR* Text);

object

A SftMaskCalendar object.

Dt

The date to be converted to a formatted string.

Text

The caller provides a formatting string or a predefined formatting string, based on which the Date Dt is formatted. If an empty string is used, the short date format is used. The formatted string is returned in Text.

TextDescription
"short"The short date format is used (as defined by the user locale).
"long"The long date format is used (as defined by the user locale).
formatting stringThe formatting string (as supported by GetDateFormat) is used to format the specified date. See below for valid formatting strings.

Comments

The FormatDate method converts a date into a displayable string.

The FormatDate method uses the Windows GetDateFormat API to format the specified date Dt.

Text can be defined as "short", "long" or as a formatting string as supported by the Windows GetDateFormat API. A formatting string can consist of one or more of the following items:

TextDescription
dDay of month (without leading zero for single-digit days)
ddDay of month (with leading zero for single-digit days)
dddDay of week as a three-letter abbreviation (using GetLocaleInfo, LOCALE_SABBREVDAYNAME)
ddddDay of week as its full name (using GetLocaleInfo, LOCALE_SDAYNAME)
MMonth (digits without leading zero for single-digit months)
MMMonth (digits with leading zero for single-digit months)
MMMMonth as a three-letter abbreviation (using GetLocaleInfo, LOCALE_SABBREVMONTHNAME)
MMMMMonth as its full name (using GetLocaleInfo, LOCALE_SMONTHNAME)
yYear as last two digits (without leading zero)
yyYear as last two digits (with leading zero)
yyyyYear represented by full four digits.
ggPeriod/era string (using GetLocaleInfo, CAL_SERASTRING). This is ignored if the date to be formatted does not have an associated era or period string.

Literal characters must be enclosed by single quotes:

Text = "dddd, MMMM d 'in the year' yyyy"

To specify a literal single quote, use two quotes:

Text = "dddd, MMMM d 'in '''yy"

Calendar.FormatDateV is used for languages such as VBScript, which are limited by requiring Variant arguments and do not support strongly typed arguments for return values.

Examples

C# View entire sample code

private void Form1_Load(object sender, System.EventArgs e)
{
    string FmtVal;
    axSftMask1.Calculator.FormatCurrency(48533.85, -1, -1, -1, "", "", -1, -1, "", out FmtVal);
    MessageBox.Show(FmtVal);

    string Text;
    Text = "short";
    axSftMask1.Calendar.FormatDate(new DateTime(2000, 8, 1), ref Text);
    MessageBox.Show(Text);
    Text = "long";
    axSftMask1.Calendar.FormatDate(new DateTime(2000, 8, 1), ref Text);
    MessageBox.Show(Text);
    Text = "dddd, MMMM d 'in the year' yyyy";
    axSftMask1.Calendar.FormatDate(new DateTime(2000, 8, 1), ref Text);
    MessageBox.Show(Text);

VB.NET View entire sample code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim FmtVal As String
    AxSftMask1.Calculator.FormatCurrency(48533.85, -1, -1, -1, "", "", -1, -1, "", FmtVal)
    MsgBox(FmtVal)

    Dim Text As String
    Text = "short"
    AxSftMask1.Calendar.FormatDate(#8/1/2000#, Text)
    MsgBox(Text)
    Text = "long"
    AxSftMask1.Calendar.FormatDate(#8/1/2000#, Text)
    MsgBox(Text)
    Text = "dddd, MMMM d 'in the year' yyyy"
    AxSftMask1.Calendar.FormatDate(#8/1/2000#, Text)
    MsgBox(Text)

C++ View entire sample code

    m_pMask1 = m_Mask1.GetControlUnknown();
    _ASSERT(m_pMask1 != NULL);

    CComBSTR FmtVal;
    m_pMask1->Calculator->FormatCurrency(48533.85, -1, -1, -1, _bstr_t(_T("")), _bstr_t(_T("")), -1, -1, _bstr_t(_T("")), &FmtVal);
    AfxMessageBox(CString(FmtVal));

    FmtVal = _T("short");
    m_pMask1->Calendar->FormatDate(COleDateTime(2000, 8, 1, 0,0,0), &FmtVal);
    AfxMessageBox(CString(FmtVal));

    FmtVal = _T("long");
    m_pMask1->Calendar->FormatDate(COleDateTime(2000, 8, 1, 0,0,0), &FmtVal);
    AfxMessageBox(CString(FmtVal));

    FmtVal = _T("dddd, MMMM d 'in the year' yyyy");

See Also SftMaskCalendar Object | Object Hierarchy


Last Updated 11/15/2026 - (email)
© 2026 Softel vdm, Inc.