Convert String to SYSTEMTIME

This tip submitted by Saddam Abu Ghaida on 2012-10-26 09:04:18. It has been viewed 3188 times.
Rating of 1.0 with 1 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;
} SYSTEMTIME


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

    memset(&systime,0,sizeof(systime));
    // Date string should be "yyyy-MM-dd hh:mm"
    sscanf_s(dateTimeString, "%d-%d-%d%d:%d:%d", 
                            &systime.wYear, 
                            &systime.wMonth,
                            &systime.wDay,
                            &systime.wHour,
                            &systime.wMinute);
    return systime;
}




More tips

Help your fellow programmers! Add a tip!