Given Date, Get Day of Week - SYSTEMTIME

user195488 picture user195488 · Jun 10, 2010 · Viewed 10.5k times · Source

Is it possible to determine the day of the week, using SYSTEMTIME, if a date (month-day-year) is provided or is this structure one-way only?

What is the most lightweight way to accomplish what I am asking if SYSTEMTIME cannot do it (using Win32)?

Answer

xtofl picture xtofl · Jun 10, 2010

According to the msdn, the wDayOfWeek member is ignored when converting SYSTEMTIME to FILETIME. When converting back, it's filled in.

SYSTEMTIME t = { 2010, 6, -1 /*ignored*/, 11 };
FILETIME ft;
HRESULT hrto   = SystemTimeToFileTime( &t, &ft );
HRESULT hrback = FileTimeToSystemTime( &ft, &t );

WORD dayofweek = t.wDayOfWeek;