Export (0) Print
Expand All
div
eof
Expand Minimize

_strdate, _wstrdate 

Copy current system date to a buffer. These functions are deprecated because more secure versions are available; see _strdate_s, _wstrdate_s.


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.

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

More secure versions of these functions are available; see _strdate_s, _wstrdate_s. It is 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.

Generic-Text Routine Mappings
TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined

_tstrdate

_strdate

_strdate

_wstrdate

Routine Required header Compatibility

_strdate

<time.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_wstrdate

<time.h> or <wchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

// crt_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 instead
}

Sample Output

OS date: 04/25/03

Community Additions

ADD
Show:
© 2014 Microsoft