Date and Time

Please share your functions/code-snips

Date and Time

Postby pappawinni » Sun Feb 14, 2010 10:34 pm

many years ago I was creating a database application where I wanted to insert the german holydays automatically but
found it very difficult to calculate the easter date. From informations I found in books I develloped a formula to be able
to at least calculate the easter date for the next 100 years .
Some month later I found a book with the gauss algorithm and was frustrated to have spent so much time for creating a formula..

Nowadays there is the internet and you easily find rules - simpler then gauss - to calculate the easter date.
Or you directly find program code :)

Code: Select all
Public function CalcGregEasterDate( ByVal intYear as integer ) as date
 
' rule acc. http://www.arndt-bruenner.de/mathe/scripts/osterdatum.htm

Dim intA as integer , intB as integer , intC as integer , intD as integer , intE as integer , intF as integer , intG as integer
Dim intH as integer , intI as integer , intK as integer , intL as integer , intM as integer , intN as integer , intP as integer
Dim dtA as date

dtA = dateserial(intYear,1,1)

if intYear > 1582 then
  ' gregorian
  intA = intYear mod 19
  intB = int(intYear / 100)
  intC = intYear mod 100
  intD = int(intB / 4)
  intE = intB mod 4
  intF = int((intB +8) / 25)
  intG = int((intB - intF + 1) / 3)
  intH = (19 * intA + intB - intD - intG + 15) mod 30
  intI = int(intC / 4)
  intK = intC mod 4
  intL = (32 + 2 * intE + 2 * intI - intH - intK) mod 7
  intM = int((intA + 11 * intH + 22 * intL) / 451)
  intN = int((intH + intL - 7 * intM + 114) / 31)
  intP = (intH + intL - 7 * intM + 114) mod 31
 
  dtA = dateserial(intYear , intN , intP + 1) 
end if

return dtA
end function

? CalcGregEasterDate(2010)
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany

Re: Date and Time

Postby berndnoetscher » Mon Feb 15, 2010 9:05 am

Very nice. Thanks. :)
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: Date and Time

Postby pappawinni » Tue Jul 06, 2010 4:48 pm

The last day of the month can be calculated like that:

Code: Select all
function f_LastDayOfMonth( Optional dtDate as date )

/*
calculates Last Day in Month
by W.Oestreicher
*/

dim sDate as date

If IsMissing(dtDate) Then
  sDate = now
else
  sDate = dtDate
end if

sDate = dateadd("d",daysInMonth(sDate)-1,DateSerial(Year(sDate), Month(sDate), 1))

return sDate

end function

? f_LastDayOfMonth()


Use any date as parameter.
If no parameter is used, the last day of month is calculated from current date.
Pappa makes everything what otherwise none likes :)
pappawinni
 
Posts: 192
Joined: Tue Jan 19, 2010 11:27 pm
Location: Germany


Return to User-Functions

cron