What's today's WEEKDAY name and other general ?'s


Can you help me out? Stuck again.

I am trying to set a variable depending upon which day of the week it is.

so far I have this:

      SYSTEMTIME systemtime;
      char TheTime[19];
      GetSystemTime( &systemtime );
      sprintf (TheTime, "%04d:%02d:%02d: %02d:%02d:%02d :%04d ",
            systemtime.wYear, systemtime.wMonth, systemtime.wDay, systemtime.wHour, systemtime.wMinute, systemtime.wSecond, systemtime.wMilliseconds);
      MessageBox(NULL, TheTime, "N o w", MB_OK);

but I need a switch statement, like:

case "Monday", "Tuesday", "Friday"
     mystruct.myvar = true;
case "Wednesday", "Thursday", "Saturday"
     mystruct.myvar =false;
      mystruct.myvar =false;

Man, I get so close to thinking I have a good handle on this, then the simplest of tasks proves to be quite the challenge!

How do I extract the weekday name from my code above?

AND LASTLY please explain something to me , what are the "rules" for using strlen ?

How come it works with some strings and not others?

For instance, this code:

        int bRet;
      int iComputerNameLength;

      // Get and display the name of the computer.
      bufCharCount = MAX_COMPUTERNAME_LENGTH+1;
      bRet = GetComputerName( infoBuf, &bufCharCount );

why does if(lstrlenA(infoBuf)>=5){... work and not


I must be missing something here.... I can use some functions but not others???

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

switch(  systemtime.wDayOfWeek ){
case 1: case 2: case 5: { mystruct.myvar = true; } break;
case 3: case 4: case 6: { mystruct.myvar = false; } break;
default: { mystruct.myvar = false; } break;
you should look at the win32.hlp or msdn doc how SYSTEMTIME is defined and that SYSTEMTIME.wDayOfWeek holds what youre looking for. a 0 is sunday, 1 is monday, 2 tuesday and so on. thats more useful than full names, because windows doesnt run in english languages only...
>>>> a 0 is sunday, 1 is monday, 2 tuesday ...

In C++ usually you would define an enum like that:


Then, you might have a static array for outputting names:

static char* daysOfWeek[WEEKDAYS] =

switch(  systemtime.wDayOfWeek )
   case MONDAY: case TUESDAY: case FRIDAY:
       mystruct.myvar = true;
       mystruct.myvar = false;

>>>> How come it works with some strings and not others?

The problem is TCHAR type. It's a typedef that is either a single byte or 'char' type (ANSI) or a double-byte or wchar_t type (UNICODE). The latter is the case if the macro _UNICODE was defined in your project settings.

strlen only accepts (const) char* type but not a wchar_t*.

The way out is to use _tcslen which is defined to fit to TCHAR type regardless whether it is a char or wchar_t

You may check the article "strlen, wcslen, _mbslen, _mbstrlen" in MSDN to learn more.

Regards, Alex


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.