Solved

How do I get the Day of week?

Posted on 2001-06-11
6
381 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

18 Experts available now in Live!

Get 1:1 Help Now