I'm looking for code that can help me determine which day of the week it is, when the intput is just DD/MM/YYYY.
(where the D's are days, the M's is month and Y's is year)
If anyone can help me out, that'd be great!
Printable View
I'm looking for code that can help me determine which day of the week it is, when the intput is just DD/MM/YYYY.
(where the D's are days, the M's is month and Y's is year)
If anyone can help me out, that'd be great!
You need a know day. ie 01/Jan/2002 == TUE
Then find the difference in days to the known.
Divide by 7 using the % operator.
Add the return to the known to find the day of the week.
need to have an array of the number of days in a month
iMonthArray[12]={31,28,31,.......(note the first has to be the KNOWN month and loop Dec->Jan)
and one for the day of the week
sDay[7][64]={"Tuesday","Wednesday",....(note the first has to be the KNOWN day.)
ie 28 Feb 2002
iDiffYears=0
iDiffMonth=1
iDiffDay=27
some macros could helpCode:for(i=0;i<iDiffMonth;i++)
{
iDayDiff+=iMonthArray[i];
}
iDay=iDayDiff%7;
sprintf(sDay,"Date is a %s",sDay[iDay]);
if you store the data as a long int
ie 01/Jan/2002 = 01012002
ie 28/Feb/2002 = 28022002
Then look for leap years and you are homeCode:#define GETDAY(lDate) (lDate / 1000000)
#define GETMONTH(lDate) ((lDate / 10000) % 100)
#define GETYEAR(lDate) (lDate % 10000)
Use The code Given Below
main()
{
int x,y,z;
long int n,a,b,c;
clrscr();
cout<<"Enter Any Date in (dd/mm/yyyy) format "<<endl;
cin>>x;cin>>y;cin>>z;
if(y<=2)
{
a=z-1;
b=y+13;
}
else
{
a=z;
b=y+1;
}
n=((1461*a)/4)+((153*b)/5)+x;
c=((n-621049)%7);
switch(c)
{
case 0 : cout<<"The Day Is Sunday"<<endl;
break;
case 1 : cout<<"The Day Is Monday"<<endl;
break;
case 2 : cout<<"The Day Is Tuesday"<<endl;
break;
case 3 : cout<<"The Day Is Wednesday"<<endl;
break;
case 4 : cout<<"The Day Is Thursday"<<endl;
break;
case 5 : cout<<"The Day Is Friday"<<endl;
break;
case 6 : cout<<"The Day Is Saturday"<<endl;
break;
}
If You Dont Get It then mail me at
kathireshn2001@yahoo.co.in
I don't understand some of the constants.
1461 = 4 * 365.25 (OK)Code:n=((1461*a)/4)+((153*b)/5)+x;
c=((n-621049)%7);
Why (153*b)/5 ? (average days per month?)
Where does 621049 come from? (621049/365.25 = some day in 300AD)
Have you taken into account the change to the Gregorian calendar?