# Thread: Last Day of Month

1. ## Last Day of Month

Hi,
Could anyone tell me how to calculate what the last day of a given month is?

2. ## Re: Last Day of Month

Hi,

You can write your own calendar function for this. SilkTest does not provide any method to get the last day if any given month.

You can just create function which accepts month and year. You put a check for leap year and the rest will remain same.

If i get some spare time, i will surely write a function and post it here.

3. ## Re: Last Day of Month

I've done this before (though not in silktest), and it turns out that the simplistic algorithm is always to find the first day of the next month, and subtract one day. Saves faffing around with months of varying lengths, leap years, and so on.

4. ## Re: Last Day of Month

I got this using the method below.

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">// Find the Last day of the Month
datetime GetLastDayOfAMonth(datetime dtDate)
string sDate = FormatDate(dtDate)
integer iMonth = Val(GetField(sDate, &quot;/&quot;, 1))
integer iYear = Val(GetField(sDate, &quot;/&quot;, 3))
if (iMonth == 12)
iMonth = 1
iYear++
else
iMonth++
string sNextMonth = &quot;{Str(iMonth)}/1/{Str(iYear)}&quot;
return dtLastDayOfMonth</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">The FormatDate() function formats date layout, use - or /. and FormatStringToDatetime formats string to DateTime Datatype.

#### 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.