[Gambas-user] extracting a fractional year from a date

Benoît Minisini gambas at ...1...
Wed Nov 6 03:16:00 CET 2013


Le 06/11/2013 03:04, Kevin Fishburne a écrit :
> If you have a Date, is there a reasonably simple way to extract which
> fraction of the year it is? For example a date of 12:00 am on January
> 1st would return zero and 11:49 pm on December 31st would return one.
> The stuff I'm trying now using the Month and Day functions
> seems...wrong. If there's no obvious way to do this I'll keep hacking at it.
>

The problem is that a year can have 365 or 366 days.

If you don't care, do:

(MyDate - Date(Year(MyDate), 1, 1)) /
(Date(Year(MyDate)+1,1,1) - Date(Year(MyDate), 1, 1))

-- 
Benoît Minisini




More information about the User mailing list