|
-
Mar 9th, 2005, 04:22 AM
#1
Thread Starter
Addicted Member
last day of month
how can i get the last day of a current month withought looping from 31 and down?
thnaks i nadvance
peleg
-
Mar 9th, 2005, 04:34 AM
#2
Lively Member
Re: last day of month
I think you can't get it with one line code or single function call.
You must write a function for this or you can construct an array include every month's last day. But in both two ways you must consider leap years also.
May be it is easier to find the next month's first day then step back 1 day by using dateadd function.
Last edited by sishe; Mar 9th, 2005 at 04:38 AM.
System Halted..
-----------------------------------------
Sishe
-
Mar 9th, 2005, 04:37 AM
#3
Re: last day of month
Like this:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim a As Integer
Dim b As Integer
Dim c As Date
Dim lastday As Date
a = Month(Now) + 1
b = Year(Now)
If a = 13 Then a = 1: b = b + 1 ' Special code for December
c = Format(a & "/1/" & b, "mm/dd/yy")
lastday = DateAdd("d", c, -1)
MsgBox lastday & " " & Format(lastday, "ddd")
End Sub
One more for the library
Last edited by dglienna; Mar 9th, 2005 at 04:40 AM.
-
Mar 9th, 2005, 04:51 AM
#4
Lively Member
Re: last day of month
David you use Format function to set the date. What is the difference, in fact what is the advantages/disadvantages of using DateSerial function instead of Format?
I have to use DateSerial function because in here people use different date formats, some use US (mm/dd/yy) but some use Turkish (dd/mm/yyyy). As a result I think I will have problems with Format. What do you think?
System Halted..
-----------------------------------------
Sishe
-
Mar 9th, 2005, 04:51 AM
#5
Re: last day of month
another using dateserial.
VB Code:
Format(DateSerial(Year(Now), Month(Now) + 1, 0), "ddd")
casey.
-
Mar 9th, 2005, 04:58 AM
#6
Re: last day of month
There really is no difference. Personal preference.
format uses the format of the machine, you have to use that
not an issue in the US, though
Wasn't sure if you wanted the date or the day, so I included both.
Casey, nice trick. Didn't think to use 0.
-
Jun 15th, 2005, 10:55 PM
#7
Junior Member
Re: last day of month
Try This One....
VB Code:
Function FindLastDay(ddate As Date) As Integer
ddate = DateAdd("d", 1 - Day(ddate), ddate)
FindLastDay = DatePart("d", DateAdd("d", -1, DateAdd("M", 1, ddate)))
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|