Redigera

Dela via


_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