Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

GetDateFormat function

Formats a date as a date string for a locale specified by the locale identifier. The function formats either a specified date or the local system date.

Note  For interoperability reasons, the application should prefer the GetDateFormatEx function to GetDateFormat because Microsoft is migrating toward the use of locale names instead of locale identifiers for new locales. Any application that will be run only on Windows Vista and later should use GetDateFormatEx.


int GetDateFormat(
  _In_            LCID       Locale,
  _In_            DWORD      dwFlags,
  _In_opt_  const SYSTEMTIME *lpDate,
  _In_opt_        LPCTSTR    lpFormat,
  _Out_opt_       LPTSTR     lpDateStr,
  _In_            int        cchDate


Locale [in]

Locale identifier that specifies the locale this function formats the date string for. You can use the MAKELCID macro to create a locale identifier or use one of the following predefined values.

dwFlags [in]

Flags specifying date format options. For detailed definitions, see the dwFlags parameter of GetDateFormatEx.

lpDate [in, optional]

Pointer to a SYSTEMTIME structure that contains the date information to format. The application sets this parameter to NULL if the function is to use the current local system date.

lpFormat [in, optional]

Pointer to a format picture string that is used to form the date. Possible values for the format picture string are defined in Day, Month, Year, and Era Format Pictures.

The function uses the specified locale only for information not specified in the format picture string, for example, the day and month names for the locale. The application can set this parameter to NULL to format the string according to the date format for the specified locale.

lpDateStr [out, optional]

Pointer to a buffer in which this function retrieves the formatted date string.

cchDate [in]

Size, in characters, of the lpDateStr buffer. The application can set this parameter to 0 to return the buffer size required to hold the formatted date string. In this case, the buffer indicated by lpDateStr is not used.

Return value

Returns the number of characters written to the lpDateStr buffer if successful. If the cchDate parameter is set to 0, the function returns the number of characters required to hold the formatted date string, including the terminating null character.

The function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError, which can return one of the following error codes:

  • ERROR_INSUFFICIENT_BUFFER. A supplied buffer size was not large enough, or it was incorrectly set to NULL.
  • ERROR_INVALID_FLAGS. The values supplied for flags were not valid.
  • ERROR_INVALID_PARAMETER. Any of the parameter values was invalid.


See Remarks for GetDateFormatEx.

When the ANSI version of this function is used with a Unicode-only locale identifier, the function can succeed because the operating system uses the system code page. However, characters that are undefined in the system code page appear in the string as a question mark ("?").

Starting with Windows 8: GetDateFormat is declared in Datetimeapi.h. Before Windows 8, it was declared in Winnls.h.


Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Minimum supported phone

Windows Phone 8


Datetimeapi.h (include Windows.h)





Unicode and ANSI names

GetDateFormatW (Unicode) and GetDateFormatA (ANSI)

See also

National Language Support
National Language Support Functions
Day, Month, Year, and Era Format Pictures



© 2017 Microsoft