Hello.
If I want to find Maxdate of each Month
what is function ?
thank you.
Hello.
If I want to find Maxdate of each Month
what is function ?
thank you.
Hi,
There isn’t a built in function for that, but making your own is not difficult. Anyway you have the code you need here:
http://forums.realsoftware.com/viewtopic.php?f=1&t=41786
Julen
Perhaps you are searching for an other function:
Testing if the date is a correct date, use this:
Dim theDate as New Date
Dim converted as Boolean
converted = ParseDate("32.12.2013", theDate)
If converted then
MsgBox("Correct: " + theDate.AbbreviatedDate)
Else
MsgBox("WRONG!")
End If
32.12.2013 is the german notation.
If you using a US-Layout, you have to use, 12/32/2013.
12/32/2013 is showing wrong
12/31/2013 is showing correct
Alwyn Bester
I’m run excample code of you but error --> MsgBox Str(d.MaxDays)
Make sure the following method is added to a module in your project…
Function MaxDays(extends d As Date) As Integer
Dim days As Integer
days = 31
select case d.Month
case 4, 6, 9, 11
days = 30
case 2
if (d.Year mod 4) = 0 then
days = 29
else
days = 28
end if
end select
return days
End Function
…then the following should work
Dim d as new Date
MsgBox Str(d.MaxDays)
You can download the example project here…
This is really simple:
dim the variables
bol = parsedate(“first day of the following month in whatever way you write your dates”, d)
d.totalseconds = d.totalseconds - 86400 (606024)
d.day is your answer
works for 01Jan, leap years, you name it
Gerd
[quote=43021:@Alwyn Bester]Make sure the following method is added to a module in your project…
case 2
if (d.Year mod 4) = 0 then
days = 29
else
days = 28
end if
end select
[/quote]
Be careful, mod 4 is not enough. Every 100 years it’s 28 instead of 29.
Didn’t realize this, thanks for pointing it out.
Gerd’s solution then looks like a more elegant solution.
For the sake of interest… here is the fixed method… from a quick Google search it appears that years that are divisible by 100 AND 400 are also leap years (e.g. 2000)
Function MaxDays(extends d As Date) As Integer
Dim days As Integer
days = 31
select case d.Month
case 4, 6, 9, 11
days = 30
case 2
if ((d.Year mod 4) = 0) then
if (d.Year mod 100) <> 0 then
days = 29
else
if (d.Year mod 400) = 0 then
days = 29
else
days = 28
end if
end if
else
days = 28
end if
end select
return days
End Function