#152386 - 2005-11-28 08:08 PM
Last day of the month
|
Stanley
Starting to like KiXtart
Registered: 2004-06-03
Posts: 130
Loc: Upstate NY, USA
|
Good day all. I am trying to determine the last day of each month programmatically and this is the best I can come up with. Thanks to Rob van der Woude for the leap year bit. I have RTFM and searched here, but no luck. So I took a stab at it. Please be gentle.
Code:
;Last day of each month $a = "31","28","31","30","31","30","31","31","30","31","30","31"
; Initialize $LeapYear = 0 ; A leap year is any multiple of 4... $Test = $Year / 4 $Test = $Test * 4 If $Year = $Test $LeapYear = 1 EndIf ; ...except If it is a multiple of 100... $Test = $Year / 100 $Test = $Test * 100 If $Year = $Test $LeapYear = 0 EndIf ; ...unless it is a multiple of 400! $Test = $Year / 400 $Test = $Test * 400 If $Year = $Test $LeapYear = 1 EndIf
;Reset the value in the array If $LeapYear = 1 $a[1] = 29 EndIf
;Last day of the current month $ld = $a[@MONTHNO - 1]
_________________________
Taxation WITH representation isn't so hot, either!
|
|
Top
|
|
|
|
#152387 - 2005-11-28 08:26 PM
Re: Last day of the month
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
I made a few UDF a while back that would help out with this.
ReturnCTDays(), ReturnCTMonths(), and you will need FlipCTime() and CTime() UDF's
Code:
$days = ReturnCTDays(2004,2) ? ctime($days[ubound($days)])
|
|
Top
|
|
|
|
#152390 - 2005-11-29 12:49 AM
Re: Last day of the month
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
You could look at fnIsDate() for some ideas.
|
|
Top
|
|
|
|
#152391 - 2005-11-29 12:53 AM
Re: Last day of the month
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Here is another way of doing it...
Code:
$y=@YEAR $l=(Right($y*25,2)='00') and ((Right($y,2)<>'00') or (Right($y*25,4)='0000'))
Edited by Chris S. (2005-11-29 12:55 AM)
|
|
Top
|
|
|
|
#152392 - 2005-11-29 09:40 AM
Re: Last day of the month
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Or even: Code:
$iLeapYear=Not(@YEAR MOD 400) OR (@YEAR MOD 100) AND Not(@YEAR MOD 4)
|
|
Top
|
|
|
|
#152393 - 2005-11-29 04:15 PM
Re: Last day of the month
|
Stanley
Starting to like KiXtart
Registered: 2004-06-03
Posts: 130
Loc: Upstate NY, USA
|
The power of the phrase "Golfed it down" amazes me.
But seriously, Thanks to all for your most excellent suggestions.
I have decided to go with this.
Code:
;Create an array of Last day of each month $mld = "31","28","31","30","31","30","31","31","30","31","30","31"
;Calculate if Leap Year $LeapYear= Not(@YEAR MOD 400) OR (@YEAR MOD 100) AND Not(@YEAR MOD 4)
;Reset the February value in the array if this is a Leap Year If $LeapYear = 1 $mld[1] = 29 EndIf
;Get Last day of the current month from $mld array $ld = $mld[@MONTHNO - 1]
_________________________
Taxation WITH representation isn't so hot, either!
|
|
Top
|
|
|
|
#152395 - 2005-11-30 10:48 AM
Re: Last day of the month
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
A lot of KiXtart users play golf as a hobby ;-)
...and some of us can never let it go : Code:
;Create an array of Last day of each month $mld = "31","28","31","30","31","30","31","31","30","31","30","31" ; Determine number of days in February $mld[1]=28+(Not(@YEAR MOD 400) OR (@YEAR MOD 100) AND Not(@YEAR MOD 4)) ;Get Last day of the current month from $mld array $ld = $mld[@MONTHNO-1]
|
|
Top
|
|
|
|
#152398 - 2005-12-01 11:01 PM
Re: Last day of the month
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Mini Golf ??
Slightly modified version of Richard's code 
Code:
;Create an array of Last day of each month with buieldin leapyar check $mld = 31,28+(Not(@Year Mod 400) Or (@Year Mod 100) And Not(@Year Mod 4)),31,30,31,30,31,31,30,31,30,31 ;Get Last day of the current month from $mld array $ld = $mld[@MonthNo-1]
I got curious: Can you build an array of integer values for last day of month, with encapsulated code for february?
At least with KiX 4.51 you can! (previous code works)
-Erik
|
|
Top
|
|
|
|
#152399 - 2005-12-02 10:39 AM
Re: Last day of the month
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Hah! That's delightful.
Funny how obvious these things are once someone else has done the work
|
|
Top
|
|
|
|
#152400 - 2005-12-02 03:35 PM
Re: Last day of the month
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
I can't resist...
Code:
;Create an array of Last day of each month with builtin leapyar check $o=0,3-(Not(@Year Mod 400) Or (@Year Mod 100) And Not(@Year Mod 4)),0,1,0,1,0,0,1,0,1,0 ;Get Last day of the current month from $o array $d=31-$o[@MonthNo-1]
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 525 anonymous users online.
|
|
|