{"id":289,"date":"2015-04-09T00:19:11","date_gmt":"2015-04-08T22:19:11","guid":{"rendered":"http:\/\/blog.teleranek.org\/?p=289"},"modified":"2025-06-29T12:29:13","modified_gmt":"2025-06-29T10:29:13","slug":"how-to-get-the-week-number-in-a-month","status":"publish","type":"post","link":"https:\/\/blog.teleranek.org\/?p=289","title":{"rendered":"How to get the week number in a month"},"content":{"rendered":"<p>Recently I wanted to display a number of week in a month. At first I wanted to get the formula from google instead of thinking, but there was no such formula. Also, I&#8217;ve found a lengthy discussion and only some indian guy gave the formula (which was incorrect of course:D)<\/p>\n<p>Suppose that November the 1st is Thursday. Then for example, November 2nd is a 1st week of November, November 16th is a 3rd week, 30th is 5th week (basing on a fact that Monday starts the week)<br \/>\nHere&#8217;s the\u00a0table that illustrates it:<br \/>\n<a href=\"http:\/\/blog.teleranek.org\/wp-content\/uploads\/2015\/04\/tbl.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-293 size-full\" src=\"http:\/\/blog.teleranek.org\/wp-content\/uploads\/2015\/04\/tbl.png\" alt=\"\" width=\"713\" height=\"204\" srcset=\"https:\/\/blog.teleranek.org\/wp-content\/uploads\/2015\/04\/tbl.png 713w, https:\/\/blog.teleranek.org\/wp-content\/uploads\/2015\/04\/tbl-300x86.png 300w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/a><\/p>\n<p>?How to get the week number?<\/p>\n<p><code>~~( ( m - w + 6 ) \/ 7 )<\/code><\/p>\n<p>where <strong>m<\/strong> is an integer, a month day, 0 or 1-based<br \/>\n<strong>w<\/strong> is an integer, a week day, 0 or 1-based (e.g. Monday = 1, Thursday = 4)<\/p>\n<p>Double bitwise negation is just a conversion to integer, you can use floor if you don&#8217;t care about speed (I guess that&#8217;s the case in times of virtual machine driven emulators and regex-based [greets angular;) ] js frameworks).<\/p>\n<p>I&#8217;ll rebelliously leave it without a proof.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I wanted to display a number of week in a month. At first I wanted to get the formula from google instead of thinking, but there was no such formula. Also, I&#8217;ve found a lengthy discussion and only some indian guy gave the formula (which was incorrect of course:D) Suppose that November the 1st [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-289","post","type-post","status-publish","format-standard","hentry","category-flash-experiments"],"_links":{"self":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=289"}],"version-history":[{"count":3,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/289\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/289\/revisions\/294"}],"wp:attachment":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}