Solved

How do I get the Day of week?

Posted on 2001-06-11
6
392 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 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 58
ffmpeg - "rtsp://...... Operation not permitted" 4 89
Doc'in system (example?) BA 7 120
Path of Workbook 3 87
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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