?
Solved

How do I get the Day of week?

Posted on 2001-06-11
6
Medium Priority
?
406 Views
Last Modified: 2013-11-20
I need to grab the day of the week (1-7, Mon-Sun) from the current date in Windows.  Using Borland the command is:
  dosdate_t datep;
  _dos_getdate(&datep);
  int day_of_week=datep.dayofweek;

Does MFC have a command like this? Can anyone help me?
0
Comment
Question by:atsac
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Accepted Solution

by:
agriggs earned 240 total points
ID: 6179303
int lDay = COleDateTime::GetCurrentTime().GetDayOfWeek()

Sunday = 1

0
 

Expert Comment

by:SrinivasaRao
ID: 6179980
you  also  have CTime::GetDayOfWeek()
Sunday = 1
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 6179982
Hi,

Or try this one...

void CDayWeekDlg::PrintDayOfWeek()
{

     UINT DayOfWeek[] =
     {
          LOCALE_SDAYNAME7,   // Sunday
          LOCALE_SDAYNAME1,  
          LOCALE_SDAYNAME2,
          LOCALE_SDAYNAME3,
          LOCALE_SDAYNAME4,
          LOCALE_SDAYNAME5,
          LOCALE_SDAYNAME6   // Saturday
     };

     char chWeekday[256];
     CTime time(CTime::GetCurrentTime());   // Initialize CTime with current time

     // Get string for day of the week from system,
     // Get day of week from CTime
     ::GetLocaleInfo(LOCALE_USER_DEFAULT, DayOfWeek[time.GetDayOfWeek()-1],  
                         chWeekday, sizeof(chWeekday));

     AfxMessageBox(chWeekday);

}

VinExpert
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:ravi_pvkumar
ID: 6180045
// you can do this with two classes CTime and  
      //COleDateTime.
     // this code will get you the systime.
   
        int dayOfWeek;
        CTime tm;
     tm = CTime::GetCurrentTime();
        dayOfWeek = tm.GetCurrentTime().GetDayOfWeek();
        cout<<dayOfWeek<<endl;
       // if you want string
       CString str;
       char DayOfWeek[20];
       str = tm.Format("%A");
       strcpy(DayOfWeek,str);
       cout<<DayOfWeek<<endl;
       /// similary you can do it with the COleDateTime

     //if want to give your date time give it as
     CTime tm (2001, 6, 11, 22, 15, 0);
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6180335
See function strftime from MSDN:

MSDN: strftime, wcsftime:
=========================
size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr );

Some of possible member of format parameter are:
  %a   Abbreviated weekday name
  %A   Full weekday name
0
 

Author Comment

by:atsac
ID: 6181982
Thanks, that's what I needed.  And thanks to all the other experts for their solutions.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

650 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