How to get the week number in the month of a Date - AS3 (Actionscript 3)

How would I get the week number in the month of a Date?

I can retrieve the week number in a year w/ getWeekOfTheYear (d:Date) but a calculation based around that will prove difficult - any help is greatly appreciated

Returned value I would expect would typically range from [0 - 4]

Answers


Take a look at this aproach:

Get current calendar week

Use the function week_num to get the week number passing a date object as you wanted.


You have to account for months starting in the middle of the week, where e.g. the 1st is a Thursday.

Get the week day number of the months 1st day minus one. Add that to your current date, divide by 7, floor it, add one to the result: That's the months week (zero-based) of that day.

// be carful to provide month zero-based like AS need it to be
private function monthWeekOfDay(year:int, month:int, day:int, weekStartsOnMonday:Boolean = false):int
{
    var firstDay:int = new Date(year, month, 1).getDay();
    if (weekStartsOnMonday)
        firstDay = (firstDay + 6) % 7;
    firstDay--;

    return Math.floor((new Date(year, month, day).getDate() + firstDay) / 7);
}

Need Your Help

sort/arrange associative array by key

php arrays sorting

How to sort/arrange associative array by key,I have an array like this

Facebook Connect API issue with authentication token

api facebook oauth token file-get-contents

I have implemented the following code below according to the documentation and can get it to connect and display user id...