Hey i am doing a database of a bueaty salon with pascal. I need to tell the user to enter the date and validate it date but i on managed to get this far can u please help me. I need to validate that february contains 29 days if in a leap yr and 28 days if not. Help me plssss

Procedure Date(var Yr, Dy, WDay : word; var mnth : string);
Begin
Repeat
gotoxy(1,16);
Write('Enter year : ');
gotoxy(14,16);
Read(yr);
GetDate(Year,Month,Day,WeekDay);
Until (year = yr) Or (yr= (year + 1));
gotoxy(1,17);
Writeln('Enter month : ');
gotoxy(14,17);
Read(mnth);
Getdate(Year,Month,Day,WeekDay);
If ((yr / 4)= 0) AND (mnth = (monthstr[2])) then
month := (dy >= 1) AND (dy <= 29);

Recommended Answers

All 5 Replies

Even though I think that you give not enough data about your procedure, I can stil answer your question. To tell if it is a leap-year,
simply designate a boolean variable titled "lyear", make "yr" an integer, and do this:

if (yr div 4)=0 then lyear:=true;

How can i validate if the month has 30 or 31 days and febueay havin 28 or 29?

Well, what do you mean by validate? If it is what I think it is, do this:

if mnth='january' then mnthdays:=31;
if mnth='february' then begin 
if (yr mod 4)=0 then mnthdays:=28
else mnthdays:=29;
end;
if mnth='march' then mnthdays:=31;
if mnth='april' then mnthdays:=30;
if mnth='may' then mnthdays:=31;
if mnth='june' then mnthdays:=30;
if mnth='july' then mnthdays:=31;
 if mnth='august' then mnthdays:=31;
if mnth='september' then mnthdays:=30;
if mnth='october' then mnthdays:=31;
if mnth='november' then mnthdays:=30;
if mnth='december' then mnthdays:=31;

I have a simular program, I'm a little confuse by leap year. I thought if leap year and divisible by 4 the month is February then days range 1-29 else 1-28 then it is not leap year? I think I got my code reverse.

The SysUtils.pas file contains a function as follows:
isLeapYear (year : word) : boolean;

It also contains a Monthdays constant which is a two dimensional array. The first dimension is boolean so it is either true or false with false being the number of days for each month in a year that is not a leap year. The second dimension is an array of 12 items of type word representing the number of days in that month.

If you include sysutils in the uses clause, you can access these items.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.