Help with DATE function

Playing around with functions and I wanted to write one to give me the number of days in a particular month

function test (inputmonth,inputyear)

test=day(date(inputyear,inputmonth,1)-1)

end function

However, no matter what I pass over, the answer is always 5.

Ie, today’s date is 6 March and test(3,2019) = 5 and test(10,2021) = 5

I cannot see why it is defaulting to today’s date?

You probably want DateSerial function, that takes parameters and returns the given date, not the Date statement, that returns current date?

By the way, your design would not give you number of days in the month given as the parameter; it would give you the number of days in the preceding month.

Thank you. I thought you could use date(year,month,day) to give a particular date.

Did not know about dateserial. That did the trick.

I have never used functions before, so I was playing around and trying to teach myself.

Thanks for your help.

Given that you put Calc to the tags, doesn’t DAYSINMONTH spreadsheet function do what you need?

=DAYSINMONTH(DATE(2021;10;1))

Yes, I was learning about functions, that was all and how to use them.