Solved

How do I get the Day of week?

Posted on 2001-06-11
6
386 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
6 Comments
 
LVL 2

Accepted Solution

by:
agriggs earned 60 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

13 Experts available now in Live!

Get 1:1 Help Now