views:

317

answers:

3

On Windows Mobile (but I guess it's the same on Windows) in a native C++ app, how would I go about setting a SYSTEMTIME structure correctly? Assuming I have

int year, month, dayOfMonth, hour, minute, second;

I obviously should set the wHour, wYear, etc members of the SYSTEMTIME structure, but what happens with wDayOfWeek in that case, I would rather have this set up correctly as well. I have looked but not found any functions in MSDN that would allow me to populate a SYSTEMTIME structure where the wDayOfWeek member would be calculated for me. Did I miss something or how would I go about that?

+1  A: 

Hmm...

Maybe first construct a FILETIME and then call FileTimeToSystemTime?

Info on FILETIME
http://msdn.microsoft.com/en-us/library/ms724284(VS.85).aspx

Or, first contruct a VARIANT of VT_TIME and then callVariantTimeToSystemTime. http://msdn.microsoft.com/en-us/library/ms221440.aspx

Corey Trager
Both make sense, but how do I construct either a FILETIME or VARIANT of VT_TIME?
Steven
+3  A: 

You could fill in the fields you know, then convert to variant time and back.

That might fill in the missing data.

HS
Yep. I remember solving this problem myself, and I think I did something like this.
Scott Langham
Thanks, that was it. I tried converting it to FILETIME and then back, but this did only work with wDayOfWeek set correctly. Converting to variant time and back worked perfectly.
Steven
A: 

Some googling turns up that you need to use the doomsday rule to figure this out. There are some c++ examples and further information in the links below.

But the real solution depends on what date you have and where you get it from. Like the others have said it may be easier to turn it into a filetime and then generate the systemtime.

Will Rickards