HeaderPane
Main
Hide
Share Link
Print

CustomFormat

Defines the custom format of a date field control.

C

int SftDate_GetCustomFormat(HWND hwndCtl, LPTSTR lpszFormat, int cchMax);
int WINAPI SftDate_GetCustomFormat_A(HWND hwndCtl, LPSTR lpszFormat, int cchMax);
int WINAPI SftDate_GetCustomFormat_W(HWND hwndCtl, LPWSTR lpszFormat, int cchMax);
void SftDate_SetCustomFormat(HWND hwndCtl, LPCTSTR lpszFormat);
void WINAPI SftDate_SetCustomFormat_A(HWND hwndCtl, LPCSTR lpszFormat);
void WINAPI SftDate_SetCustomFormat_W(HWND hwndCtl, LPCWSTR lpszFormat);

C++

int CSftDate::GetCustomFormat(LPTSTR lpszFormat, int cchMax) const;
CString CSftDate::GetCustomFormat() const;
void CSftDate::SetCustomFormat(LPCTSTR lpszFormat);

Parameters

hwndCtl

The window handle of the date field control (SftDate).

lpszFormat

Get: a pointer to the buffer that receives the format, or NULL to retrieve its length.
Set: a pointer to the format. NULL is the same as an empty format.

cchMax

The size of the buffer in characters, including the terminating null character.

Returns

The Get function returns the number of characters copied to the buffer, not including the terminating null character. If the buffer is NULL or cchMax is 0, it returns the length of the text instead, so an application can allocate a buffer of the required size (the length plus one). A text longer than the buffer is truncated.

Comments

The GetCustomFormat and SetCustomFormat functions define and retrieve the format used when the format is SFTDATE_FORMAT_CUSTOM (SetFormat).

The format consists of format specifiers such as d, dd, ddd, dddd (day), M, MM, MMM, MMMM (month), y, yy, yyyy (year), g (era), h, hh, H, HH (hour), m, mm (minute), s, ss (second), f (fractions of a second), t, tt (AM/PM designator), and literal text in single or double quotes or after a backslash. A format of a single character is a standard format, for example "d" for the short date or "t" for the short time. The default is an empty format, which uses the short date format. See Formats for all specifiers.

Example: "ddd, MMM d, yyyy 'at' HH:mm" shows Fri, Dec 25, 2026 at 14:30.

Names and the AM/PM designator come from the culture (SetCulture). This function applies to the date field control only. For a month calendar control, GetCustomFormat returns 0 and SetCustomFormat has no effect.

SftDate.h maps the name without suffix to the _A (ANSI) or _W (Unicode) function, depending on whether UNICODE or _UNICODE is defined. The ANSI functions convert the text using the system code page.

Examples

C View entire sample code

    SftDate_SetAllowEmpty(GetDlgItem(hwndDlg, IDC_EMPTY), TRUE);
    SftDate_SetPlaceholderText(GetDlgItem(hwndDlg, IDC_EMPTY), TEXT("No date"));
    SftDate_SetShowClearButton(GetDlgItem(hwndDlg, IDC_EMPTY), TRUE);
    SftDate_SetValue(GetDlgItem(hwndDlg, IDC_EMPTY), NULL);

    SftDate_SetEditStyle(GetDlgItem(hwndDlg, IDC_FREEFORM), SFTDATE_EDIT_FREEFORM);

    SftDate_SetCustomFormat(GetDlgItem(hwndDlg, IDC_CUSTOM), TEXT("ddd, MMM d, yyyy 'at' HH:mm"));
    SftDate_SetFormat(GetDlgItem(hwndDlg, IDC_CUSTOM), SFTDATE_FORMAT_CUSTOM);

    SftDate_SetMonthsAcross(hwndCal, 2);

    SftDate_GetMinDate(hwndCal, &g_minDate);
    SftDate_GetMaxDate(hwndCal, &g_maxDate);

    SetDlgItemText(hwndDlg, IDC_HELPTEXT,

C++ View entire sample code

    m_Fields[7].SetAllowEmpty(TRUE);
    m_Fields[7].SetPlaceholderText(_T("No date"));
    m_Fields[7].SetShowClearButton(TRUE);
    m_Fields[7].SetValue(NULL);

    m_Fields[8].SetEditStyle(SFTDATE_EDIT_FREEFORM);

    m_Fields[9].SetCustomFormat(_T("ddd, MMM d, yyyy 'at' HH:mm"));
    m_Fields[9].SetFormat(SFTDATE_FORMAT_CUSTOM);

    m_Calendar.SetMonthsAcross(2);

    m_Calendar.GetMinDate(&m_minDate);
    m_Calendar.GetMaxDate(&m_maxDate);

    SetDlgItemText(IDC_HELPTEXT,

See Also C/C++ API | Categories | Notifications


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