Dilwyn Jones wrote:

> A help request:
> 
> Is there a way of returning the current month as a number?

I had thought I had come up with a function for this, but it is getting the 
ends of some months wrong, eg 1 May is coming out as 31 Apr! (Which seems 
odd as I thought I had checked out all the month bounds when writing the 
function...I'll have another look at it tomorrow.)

...

> Seems so clumsy I'm sure there must be a better way! I need to use it 
> in my diary program to find entries for the current day or current 
> month. The only other idea I've come up with so far is to take the 
> value of DATE as seconds from DATE=0 and try to divide by the number 
> of seconds per year and per month, taking into account leap years!

Not quite, it's just a matter of correcting for a different base: taking 
date(0)=01 Mar 1960 makes taking leap years into account dead easy[1].  It's 
just a matter of then working out the current month within the shifted year 
(also slightly easier as the days pattern is regular for the first 11 
months) and correcting for the Gregorian year.

[1] By using a year starting on 1 Mar, leap days are added after the last 
day (Feb 28 of the next Gregorian year) in the year; and don't forget that 
1960 was a leap year so the previous year in this system was a leap year and 
the next one will be in 4 years time!


_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to