Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: I want to know the current week number of the current month

by Muskovitz (Scribe)
on Oct 12, 2017 at 13:09 UTC ( [id://1201214]=note: print w/replies, xml ) Need Help??


in reply to Re: I want to know the current week number of the current month
in thread I want to know the current week number of the current month

Thanks!
As for now i think this will do!
Later on if i encounter some "0's" stuff i think i'll just sort it out with some conditional statements
  • Comment on Re^2: I want to know the current week number of the current month

Replies are listed 'Best First'.
Re^3: I want to know the current week number of the current month (updated!)
by haukex (Archbishop) on Oct 13, 2017 at 09:22 UTC
    Later on if i encounter some "0's" stuff i think i'll just sort it out with some conditional statements

    I'm not sure what you mean by this. If you don't want to have a week numbered zero, you could just add one to the week number, but keep in mind that some months will end up having up to six weeks and the first and last "weeks" will almost always end up having less than seven days:

    _________ Oct 2017 _________ Week 1: 01 Week 2: 02 03 04 05 06 07 08 Week 3: 09 10 11 12 13 14 15 Week 4: 16 17 18 19 20 21 22 Week 5: 23 24 25 26 27 28 29 Week 6: 30 31

    As others have said, talk to your client / boss about how they define "week of month". A common system is the ISO 8601 week number, maybe your client / boss would be happier with that system, since every week will have seven days. Also note in the following table how some weeks have two week_of_month-based "names" under the above system.

    ________________________ 2017 ________________________ Week Mon Tue Wed Thu Fri Sat Sun 52 Dec 26 27 28 29 30 31 Jan 01 (Dec Week 6, +Jan Week 1) 1 02 03 04 05 06 07 08 (Jan Week 2) 2 09 10 11 12 13 14 15 (Jan Week 3) 3 16 17 18 19 20 21 22 (Jan Week 4) 4 23 24 25 26 27 28 29 (Jan Week 5) 5 30 31 Feb 01 02 03 04 05 (Feb Week 2, +Jan Week 6) ... 39 25 26 27 28 29 30 Oct 01 (Oct Week 1, +Sep Week 5) 40 02 03 04 05 06 07 08 (Oct Week 2) 41 09 10 11 12 13 14 15 (Oct Week 3) 42 16 17 18 19 20 21 22 (Oct Week 4) 43 23 24 25 26 27 28 29 (Oct Week 5) 44 30 31 Nov 01 02 03 04 05 (Nov Week 2, +Oct Week 6) ...

    Update: Fixed bug that weekdays weren't properly aligned. Also added the week_of_month-based "names".

Re^3: I want to know the current week number of the current month
by thanos1983 (Parson) on Oct 12, 2017 at 16:15 UTC

    Hello again Muskovitz.

    Do check my latest update (update3) bellow.

    From my point of view if you want to calculate correctly the number of weeks is 3. Because this month started on Sunday (1s of October). Which means the second week was 2nd day of the month. So since we are in the 12th of October currently it makes sense to be the third week, if you calculating the weeks as they start on Monday.

    So at this point it depends on what you want to consider a week. Do you count weeks e.g. if the date is 12th then only two weeks have passed this month what if the month has 31 days and the month started on Sunday as on this case then we have 6 weeks in total if you count the beginning of a week on Monday.

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201214]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-20 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found