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

Posted on 2006-04-19
Last Modified: 2010-04-01

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???

Question by:edvinson
    LVL 84

    Assisted Solution

    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;
    LVL 12

    Assisted Solution

    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...
    LVL 39

    Accepted Solution

    >>>> 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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One C++ Help from Top Experts

    Solve your toughest problems, fast.
    C++ experts are online now and ready to help you.

    Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now