Pascal calculate day of week with given inputday - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Pascal calculate day of week with given inputday

markstar217markstar217 Posts: 3Member
Hello everyone!

I need to create a Program which first reads in DD/MM/YYYY as Integer. (I already got that working.)
Then, I need to do a sanity check for the date.
(I managed to do that as well.)

But one problem remains:
I need to enter the day of the week of the 1st of January for a year, e.g. Monday and based on that, the program should calculate the correct weekday for the inputted date.
Are there any functions I could use for this?

Any help would be kindly appreciated!

Comments

  • Dmitry_ZorinDmitry_Zorin Posts: 13Member
    Here it is, but I did it for 2012 year, to do it for every year you need to add some conditions, maybe later I'll try to do it.
  • Dmitry_ZorinDmitry_Zorin Posts: 13Member
    This post has been deleted.
  • Dmitry_ZorinDmitry_Zorin Posts: 13Member
    This post has been deleted.
  • Dmitry_ZorinDmitry_Zorin Posts: 13Member
    This post has been deleted.
  • Dmitry_ZorinDmitry_Zorin Posts: 13Member
    Here it is, but I did it for 2012 year, to do it for every year you need to add some conditions, maybe later I'll try to do it.

    Program weekday;
    const
    a1=[01,08,15,22,29]; {e.g. if 01 is Monday then 08,15.. are Mondays too}
    a2=[02,09,16,23,30];
    a3=[03,10,17,24,31];
    a4=[04,11,18,25];
    a5=[05,12,19,26];
    a6=[06,13,20,27];
    a7=[07,14,22,28];
    Var x, d,m,y:integer; w:array[1..7] of string;

    Begin
    w[1]:='Sunday';
    w[2]:='Monday';
    w[3]:='Tuesday';
    w[4]:='Wednesday';
    w[5]:='Thursday';
    w[6]:='Friday';
    w[7]:='Saturday';
    writeln('Enter current date DD MM YYYY');
    read(d,m,y);
    if y=2012 then

    begin
    write('It''s ');
    if d in a1 then x:=0;
    if d in a2 then x:=1;
    if d in a3 then x:=2;
    if d in a4 then x:=3;
    if d in a5 then x:=4;
    if d in a6 then x:=5;
    if d in a7 then x:=6;

    begin
    if (m=01) or (m=04) or (m=07) then writeln(w [1+( x mod 7)] );{To each month we define day of a week depending on group in which it is(a1,a2...,a7)}
    if (m=02) or (m=08) then writeln(w [1+( (3+x) mod 7)] );{substituting x we get necessary w[...], so get necessary weekday}
    if (m=03) or (m=11) then writeln(w [1+( (4+x) mod 7)] );
    if (m=05) then writeln(w [1+( (2+x) mod 7)] );
    if (m=06) then writeln(w [1+( (5+x) mod 7)] );
    if (m=09) or (m=12) then writeln(w [1+( (6+x) mod 7)] );
    if (m=10) then writeln(w [1+( (1+x) mod 7)] );
    end;

    end else writeln('No info about this year');

    end.
  • markstar217markstar217 Posts: 3Member
    Thank you very much for your help!
    I'll edit the code further for several years that I need.

    Thanks again! :)
Sign In or Register to comment.