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.
Syntax
int GetDateFormat( _In_ LCID Locale, _In_ DWORD dwFlags, _In_opt_ const SYSTEMTIME *lpDate, _In_opt_ LPCTSTR lpFormat, _Out_opt_ LPTSTR lpDateStr, _In_ int cchDate );
Parameters
- 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.
Remarks
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.
Requirements
|
Minimum supported client |
Windows 2000 Professional [desktop apps only] |
|---|---|
|
Minimum supported server |
Windows 2000 Server [desktop apps only] |
|
Minimum supported phone |
Windows Phone 8 |
|
Header |
|
|
Library |
|
|
DLL |
|
|
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
- EnumCalendarInfo
- EnumDateFormatsEx
- GetCalendarInfo
- GetDateFormatEx
- GetLocaleInfo
- GetTimeFormat