# Thread: How can I calculate the Days. (Particular Month)

1. ## How can I calculate the Days. (Particular Month)

I have a webtable. Webtable contains 12 columns (Jan, Feb, Mar, April, May….Etc) and 1 Row (No. Of Days). Every day Change the Numbers in the Row. (Means Ex: Aug Month Column Total Number of days in Aug is 31 Days. Today date is 21st. In Aug Month Column specify No.Of days Cell is 11 (days). (08/31/2006 – 08/21/2006).
Is their any Method to calculate the remaining days.

Thanks
sai

2. ## Re: How can I calculate the Days. (Particular Month)

30 days has September, April, June and November.
All the rest have 31, except February which as 28 if it's not a leap year, or 29 if it is a leap year.

<font class="small">Code:</font><hr /><pre>function isLeapYear(ByVal TheYear)
isLeapYear = CBool(Year(TheYear) Mod 4)
end function

function getDaysInMonth(ByVal TheMonth, ByVal TheYear)
If (TheMonth = "09") OR (TheMonth = "04") OR (TheMonth = "06") OR (TheMonth = "11") Then
getDaysInMonth = 30
ElseIf (TheMonth = "02") Then
If isLeapYear(TheYear) Then
getDaysInMonth = 29
Else
getDaysInMonth = 28
End If
Else
getDaysInMonth = 31
End If
end function

MsgBox getDaysInMonth("08", "2002")</pre><hr />

3. ## Re: How can I calculate the Days. (Particular Month)

Hi Sai,

Here wt you are testing? Your description is somewhat confusing. Anyway what i understand is it is current date is 21st Aug, 11days will be displayed in the No.of days cell and if it is 22nd Aug, 10 days will displayed in the No.of days cell. My understanding is clear , then its very simple to very the data in No.of days cell.

User For Loop wihtin that on use Select statement up to 12 cases like Jan to Dec. capture the current date and Month and calculate the days as we are giving the Total no.of days for each month in the for each case.

write all above code in VB script only.
Thats all. If not working this solution with you let me know. I will send the code.

Thanks,
Kiran .E

4. ## Re: How can I calculate the Days. (Particular Month)

Hi Kiran,
Thanks, This is my Description.It is current date is 21st Aug, 11days will be displayed in the No.of days cell and if it is 22nd Aug, 10 days will displayed in the No.of days cell. How can i write the code.

Thanks

5. ## Re: How can I calculate the Days. (Particular Month)

Here you go

msgbox fnGetDate()

Function fnGetDate()
Dim strDate
Dim intMonth
Dim intYear
Dim blnFlag

strDate=date()
intMonth=month(strDate)
intYear=Year(strDate)

If intMonth=2 Then
If isLeapYear(intYear) Then
fnGetDate = DateDiff("d", strDate, CDate(intMonth &amp; " 29" &amp; ", " &amp; intYear))
Else
fnGetDate = DateDiff("d", strDate, CDate(intMonth &amp; " 28" &amp; ", " &amp; intYear))
End If
elseif intMonth=4 or intMonth=6 or intMonth=9 or intMonth=11 then
fnGetDate = DateDiff("d", strDate, CDate(intMonth &amp; " 30" &amp; ", " &amp; intYear))
else
fnGetDate = DateDiff("d", strDate, CDate(intMonth &amp; " 31" &amp; ", " &amp; intYear))
End If

End Function

function isLeapYear(ByVal TheYear)
isLeapYear = CBool(Year(TheYear) Mod 4)
end function

6. ## Re: How can I calculate the Days. (Particular Month)

Thanks It's Working Fine.
And I have a question How can i insert This code to Particular webtable cell. Because My webtable cell value is change very day. When i insert the checkpoint It's working fine today only. Tommorrow It's Fail (Cell Value Change).

Thanks

7. ## Re: How can I calculate the Days. (Particular Mont

You can have a look on VB Date functions..

8. ## Re: How can I calculate the Days. (Particular Mont

try using this.

DateDiff("d", Day(Date), Day(CDate("01/" &amp; Month(Date + 1) &amp; "/" &amp; Year(Date)) - 1))

9. ## Re: How can I calculate the Days. (Particular Mont

You can populate the data table with the calculated values - remaining days for all the months based on the current day passed as a parameter to the function.

After that you can define a table checkpoint on the webtable which uses parameter - which picks the corresponding value from the data table for the corresponding month to check against.

#### Posting Permissions

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

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.