Solved

How do I get the Day of week?

Posted on 2001-06-11
6
391 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
Shell script to login to remote m/c and execute commands 10 78
move a line in eclipse 3 107
sum13 challenge 24 121
fizzArray2 challenge 1 90
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.

856 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