Skip to content

Latest commit

 

History

History
109 lines (83 loc) · 4.08 KB

strdate-wstrdate.md

File metadata and controls

109 lines (83 loc) · 4.08 KB
description title ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords ms.assetid
Learn more about: _strdate, _wstrdate
_strdate, _wstrdate
4/2/2020
_strdate
_wstrdate
_o__strdate
_o__wstrdate
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-time-l1-1-0.dll
DLLExport
apiref
_tstrdate
wstrdate
_wstrdate
_strdate
strdate
strdate function
dates, copying
tstrdate function
_wstrdate function
wstrdate function
_strdate function
_tstrdate function
copying dates
de8e4097-58f8-42ba-9dcd-cb4d9a9f1696

_strdate, _wstrdate

Copy current system date to a buffer. More secure versions of these functions are available; see _strdate_s, _wstrdate_s.

Syntax

char *_strdate(
   char *datestr
);
wchar_t *_wstrdate(
   wchar_t *datestr
);
template <size_t size>
char *_strdate(
   char (&datestr)[size]
); // C++ only
template <size_t size>
wchar_t *_wstrdate(
   wchar_t (&datestr)[size]
); // C++ only

Parameters

datestr
A pointer to a buffer containing the formatted date string.

Return value

Each of these functions returns a pointer to the resulting character string datestr.

Remarks

More secure versions of these functions are available; see _strdate_s, _wstrdate_s. It's recommended that the more secure functions be used wherever possible.

The _strdate function copies the current system date to the buffer pointed to by datestr, formatted mm/dd/yy, where mm is two digits representing the month, dd is two digits representing the day, and yy is the last two digits of the year. For example, the string 12/05/99 represents December 5, 1999. The buffer must be at least 9 bytes long.

If datestr is a NULL pointer, the invalid parameter handler is invoked, as described in Parameter validation. If execution is allowed to continue, these functions return -1 and set errno to EINVAL.

_wstrdate is a wide-character version of _strdate; the argument and return value of _wstrdate are wide-character strings. These functions behave identically otherwise.

In C++, these functions have template overloads that invoke the newer, secure counterparts of these functions. For more information, see Secure template overloads.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Generic-text routine mappings

TCHAR.H routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined
_tstrdate _strdate _strdate _wstrdate

Requirements

Routine Required header
_strdate <time.h>
_wstrdate <time.h> or <wchar.h>

For more compatibility information, see Compatibility.

Example

// strdate.c
// compile with: /W3
#include <time.h>
#include <stdio.h>
int main()
{
    char tmpbuf[9];

    // Set time zone from TZ environment variable. If TZ is not set,
    // the operating system is queried to obtain the default value
    // for the variable.
    //
    _tzset();

    printf( "OS date: %s\n", _strdate(tmpbuf) ); // C4996
    // Note: _strdate is deprecated; consider using _strdate_s instead
}
OS date: 04/25/03

See also

Time management
asctime, _wasctime
ctime, _ctime32, _ctime64, _wctime, _wctime32, _wctime64
gmtime, _gmtime32, _gmtime64
localtime, _localtime32, _localtime64
mktime, _mktime32, _mktime64
time, _time32, _time64
_tzset