Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

VB or VBA function for determining the last day of a month

Hi Everybody!

I need to make a VB of VBA function that determines the last day of a month. The routine should always work. Anybody got a idea?

Thanks in advance!
0
Piet_Viseelt
Asked:
Piet_Viseelt
2 Solutions
 
ahmedbahgatCommented:
what will be the arguments to pass to the function will it be , month and year?? and in what format 2/2003 or jan 2003

cheers
0
 
Piet_ViseeltAuthor Commented:
Hi Ahmedbahgat.

The format is DD-MM-YYYY

0
 
GeerdCommented:
Heej Piet,

Take a look at the function below.

Function IsUltimo(Indate As String) As Integer

Dim leap As Integer
If Val(Right$(Indate, 4)) Mod 4 = 0 Then leap = 1

Select Case Mid$(Indatum, 4, 2)
    Case "01": IsUltimo = 31
    Case "02": IsUltimo = 28 + leap
    Case "03": IsUltimo = 31
    Case "04": IsUltimo = 30
    Case "05": IsUltimo = 31
    Case "06": IsUltimo = 30
    Case "07": IsUltimo = 31
    Case "08": IsUltimo = 31
    Case "09": IsUltimo = 30
    Case "10": IsUltimo = 31
    Case "11": IsUltimo = 30
    Case "12": IsUltimo = 31
End Select

End Function

Suc 6
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bonjour-autCommented:
to get the last day of month for a given inDate:


lastDay = DateSerial(Year(inDate),Month(inDate)+1,1)-1

exeption is December:

lastDay = DateSerial(Year(inDate)+1,Month(inDate)+1,1)-1


Regards, Franz

0
 
ahmedbahgatCommented:
what do you need to know then based on that date? is it  sunday, monday, etc.... as apposed to the last day of the month of that date argument

cheers
0
 
Ryan ChongCommented:
>>exeption is December:

>>lastDay = DateSerial(Year(inDate)+1,Month(inDate)+1,1)-1

I think use the :
lastDay = DateSerial(Year(inDate),Month(inDate)+1,1)-1
should work for all instance.

:-)
0
 
joekendallCommented:
We will stick with Franz' naming convention here with inDate as the Date you will provide.

FirstDay = inDate-Day(inDate)+1
LastDay = DateAdd("m",1,inDate)-Day(inDate)

Of course, there are many ways to do it.

Joe
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now