How to find week number of year for given date


date = 1-jan-2021
here my week number should start from 1st day of every month
my expected result should be 1st week .
please help me how can i achieve this

You can use the mday to get the day of the month. Similarly wday() will return the day of the week, and yday() will return the day of the year.

>, 1, 1, 1, 1, 1, '+05:30').mday./(7.0).ceil    #=> 1

The problem is that, we expect a month to be 4 weeks, but a month could have > 28 days. If Jan 1 is 1st week, then day Jan 31 is 5th week. To get rid of 5, clamp(1, 4) will work better:

>, 1, 1, 1, 1, 1, '+05:30').mday./(7).clamp(1, 4)    # => 1

>, 1, 31, 1, 1, 1,'+05:30').mday./(7).clamp(1, 4)    # => 4
1 Like

Thank you so much!!!

Thanks for this case.

Companies that decide to outsource App Software Development need to do so for a variety of reasons. Many companies want to concentrate on their core business processes only; however, outsourcing web app development saves a lot of time and money. This is because dedicated software development teams are able to focus specifically on the requirements of the client company. These developers create custom app solutions which meet the exact technological needs of the clients. Below are some of the key advantages of outsourcing App Software Development: