Re: Month as Integer
Re: Month as Integer
- Subject: Re: Month as Integer
- From: Sun Real <email@hidden>
- Date: Fri, 1 Dec 2000 13:32:25 +1100
From Johan Solve <email@hidden>, Thursday, 30 November 2000:
>
Would it be possible to do something like this:
>
>
on GetMonthNumber()
>
set theMonth to month of (current date)
>
set theMonthList to {January:1, February:2, March:3, April:4, May:5, -+
>
June:6, July:7, August:8, September:9, October:10, -+
>
November:11, December:12}
>
return themonth of themonthlist
>
end GetMonthNumber
>
>
I know it doesn't work as it stands but maybe it's just a matter of
>
coding it right.
>
'return November of themonthlist' works fine, so the question really
>
is how you specify a named record by a variable?
The months names are constants, not variables. I haven't played with
this but I (a) don't think it could be made to work and (b) wouldn't
recommend trying to use constants as record labels in any case. The
fastest of these methods was posted by Michelle Steiner yesterday.
Whilst it makes very little difference unless you are doing it a
squillion or so times, I use this, much faster, method:
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- --
-- -- monthNumber -- -- -- -- from Emmanuel Levy --
returns an integer
-- corresponding to the current month; called by the date handlers
on monthNumber(theDate) -- pass a date object
copy theDate to dateTemp
set month of dateTemp to January
return (1 + (theDate - dateTemp + 1314864) div 2629728)
end monthNumber
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- --
Cheers,
Richard Morton
-- Great Lies of the Music Business: "The place was packed"