Convert String to SYSTEMTIME

This tip submitted by Saddam Abu Ghaida on 2012-10-26 09:04:18. It has been viewed 27804 times.
Rating of 6.3 with 48 votes

this function will take a date string and convert it to SYSTEMTIME knowing that system time is a typedef struct. The struct will look like this

typedef struct _SYSTEMTIME {
    WORD wYear;
    WORD wMonth;
    WORD wDayOfWeek;
    WORD wDay;
    WORD wHour;
    WORD wMinute;
    WORD wSecond;
    WORD wMilliseconds;

and the function will look like this
SYSTEMTIME convertStringToSystemTime(char *dateTimeString)
    SYSTEMTIME systime;

    // Date string should be "yyyy-MM-dd hh:mm"
    sscanf_s(dateTimeString, "%d-%d-%d%d:%d:%d", 
    return systime;

More tips

Help your fellow programmers! Add a tip!