Code to find the day type of day in the year?

This is a discussion on Code to find the day type of day in the year? within the C Programming forums, part of the General Programming Boards category; I'm looking for code that can help me determine which day of the week it is, when the intput is ...

  1. #1
    Unregistered
    Guest

    Question Code to find the day type of day in the year?

    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!

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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
    Code:
    for(i=0;i<iDiffMonth;i++)
    {
           iDayDiff+=iMonthArray[i];
    }
    iDay=iDayDiff%7;
    sprintf(sDay,"Date is a %s",sDay[iDay]);
    some macros could help
    if you store the data as a long int
    ie 01/Jan/2002 = 01012002
    ie 28/Feb/2002 = 28022002
    Code:
    #define		GETDAY(lDate)		(lDate / 1000000)
    #define		GETMONTH(lDate)		((lDate / 10000) % 100)
    #define		GETYEAR(lDate)		(lDate % 10000)
    Then look for leap years and you are home
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Unregistered
    Guest

    Post

    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

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    I don't understand some of the constants.

    Code:
    n=((1461*a)/4)+((153*b)/5)+x; 
    c=((n-621049)%7);
    1461 = 4 * 365.25 (OK)
    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?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 09:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21