The number of the days in a month...

# Thread: The number of the days in a month...

1. Senior Member
Join Date
Dec 1969
Posts
1,100

## The number of the days in a month...

Hi,<BR><BR>How can i find the number of the days in a month?<BR><BR>I tried this example from ASPFaqs.com but I cannot understand it...yet.<BR><BR>-----------<BR>Function NumberOfDays(iMonth, iYear)<BR> NumberOfDays = Day(DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1)))<BR>End Function<BR>-----------<BR><BR>How can I apply it here (I have to find out the medium sales per day in a month so I do a total of the sales on that month and I have to divide to the number of days in that month):<BR>-----------<BR>CurrentMonth = month(date)<BR>CurrentYear=year(date)<BR><BR>sql_s ales_medium="SELECT sum(orderitems.pricetotal) as pricetotal FROM orders INNER JOIN orderitems ON orders.orderid = orderitems.orderid where month(date_order)="& CurrentMonth &" and year(date_order) ="& CurrentYear &" and status=true "<BR><BR>set rs_sales_medium=db.execute(sql_sales_medium)<BR><B R>Function NumberOfDays(iMonth, iYear)<BR> NumberOfDays = Day(DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1)))<BR>End Function<BR>medium_sales=rs_sales_medium("pricetot al")NumberOfDays....&#039;what here?<BR><BR>while not rs_sales_medium.eof<BR>if not rs_sales_medium("pricetotal")="" or not isnull(rs_sales_medium("pricetotal")) then<BR><BR><BR><BR><BR><BR>%&#062;<BR>&#060;b&#06 2;&#060;%=fixDelimiter(medium_sales)%&#062;&#060;/b&#062; euros<BR><BR>&#060;% <BR>else<BR>response.write "&#060;b&#062;no sales this month&#060;/b&#062;"<BR>end if<BR><BR>rs_sales_medium.movenext<BR>wend<BR><BR> rs_sales_medium.close<BR>set rs_sales_medium=nothing<BR>------------<BR><BR>Any suggestions?<BR><BR>Thanks,<BR>Mircea<BR>

2. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: The number of the days in a month...

Function NumberOfDays(iMonth, iYear)<BR> NumberOfDays = Day(DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1)))<BR>End Function <BR><BR>pretty simple really<BR><BR>call the function <BR>endofMonth = NumberOFDays(11, 03)<BR><BR><BR>lets take the DateSerial part ---<BR><BR>this creates a new date which is the DateSerial(03, 11 + 1, 1)<BR>which gives 03, 12, 1 the first of next month<BR> <BR>then DateAdd("d", -1, &#060;...&#062;) subtracts one day from that!<BR>giving the Last day of this month<BR><BR>Day(&#060;...&#062;) returns just the day portion of that

3. Senior Member
Join Date
Dec 1969
Posts
449

## to call the function

NumberOfDays(CurrentMonth, CurrentYear)<BR><BR>ie<BR>medium_sales=rs_sales_me dium("pricetotal")NumberOfDays(CurrentMonth, CurrentYear)<BR><BR>Not sure why you use rs_sales_medium("pricetotal") AND then check if there is a valid value in the wend loop.<BR>Should check the value first.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•