{"id":12125,"date":"2010-02-10T23:11:57","date_gmt":"2010-02-10T21:11:57","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=12125"},"modified":"2010-02-12T00:16:52","modified_gmt":"2010-02-11T22:16:52","slug":"php-date-and-53-weeks","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/","title":{"rendered":"PHP date() and 53 weeks"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>Let&#8217;s say you have a bunch of statistical data. \u00a0And all that data is date-related. \u00a0And let&#8217;s say want to display that data on a chart, a weekly average or something along those lines. \u00a0One of the ways for you to place the value into the proper week would be something like this:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$week = date('W', strtotime($stats_date));\r\n$values&#x5B;$week]&#x5B;] = $stats_value;\r\n<\/pre>\n<p>And if you did it this way, sooner or later, you&#8217;d notice that something is not quite working right at the edges of your chart. \u00a0With code as simple and straight-forward as this, you&#8217;d probably look for the problem elsewhere. \u00a0Maybe it&#8217;s your statistical data which is wrong, or the graph is not generated properly. \u00a0But the problem is here.<\/p>\n<p>How many weeks do you think there are in a year? \u00a0A common knowledge says 52. \u00a0However, if you think for a moment about how the weeks are related to the year, you&#8217;ll realize that the first and last weeks don&#8217;t necessary start and end at the edge of the year. \u00a0If you play around with 1st of January and 31st of December across several years, you&#8217;ll notice that sometimes they fall into the 53rd week. \u00a0(As do a few more days, not just these two).<\/p>\n<p>And here, the problem with the &#8220;W&#8221; date() format starts to emerge. \u00a0 When scattering your data across a single year, you&#8217;d most often expect January to start with the first week of the year. \u00a0But it doesn&#8217;t. Sometimes the start of it falls into the 53rd week of the previous year. \u00a0And <em>date(&#8216;W&#8217;, $your_time)<\/em> will happily return 53. \u00a0What will this do to your chart? \u00a0Two things are most likely. \u00a0The first week&#8217;s values would get reduced, and the last week&#8217;s values would get increased. \u00a0Or those values of the first week would altogether vanish from the graph. \u00a0That is unless you are careful. \u00a0Which I hope you&#8217;ll now be.<\/p>\n<p>See comments to <a href=\"http:\/\/php.net\/manual\/en\/function.date.php\">PHP date() manual<\/a> for several solutions of this problem.<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>Let&#8217;s say you have a bunch of statistical data. \u00a0And all that data is date-related. \u00a0And let&#8217;s say want to display that data on a chart, a weekly average or something along those lines. \u00a0One of the ways for you to place the value into the proper week would be something like this: $week = &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">PHP date() and 53 weeks<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false,"_links_to":"","_links_to_target":""},"categories":[1,18],"tags":[38,74],"keyring_services":[],"class_list":["post-12125","post","type-post","status-publish","format-standard","hentry","category-general","category-programming","tag-php","tag-tips"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Let&#039;s say you have a bunch of statistical data. And all that data is date-related. And let&#039;s say want to display that data on a chart, a weekly average or something along those lines. One of the ways for you to place the value into the proper week would be something like this: [php] $week\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Leonid Mamchenkov\"\/>\n\t<meta name=\"google-site-verification\" content=\"VHvdD0_usx1_4DzKy_QCVcICVgX2EgA2ybELT-wl7kQ\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Leonid Mamchenkov - Life, universe, and everything else\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"PHP date() and 53 weeks - Leonid Mamchenkov\" \/>\n\t\t<meta property=\"og:description\" content=\"Let&#039;s say you have a bunch of statistical data. And all that data is date-related. And let&#039;s say want to display that data on a chart, a weekly average or something along those lines. One of the ways for you to place the value into the proper week would be something like this: [php] $week\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2010-02-10T21:11:57+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2010-02-11T22:16:52+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/MamchenkovBlog\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@mamchenkov\" \/>\n\t\t<meta name=\"twitter:title\" content=\"PHP date() and 53 weeks - Leonid Mamchenkov\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Let&#039;s say you have a bunch of statistical data. And all that data is date-related. And let&#039;s say want to display that data on a chart, a weekly average or something along those lines. One of the ways for you to place the value into the proper week would be something like this: [php] $week\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@mamchenkov\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#blogposting\",\"name\":\"PHP date() and 53 weeks - Leonid Mamchenkov\",\"headline\":\"PHP date() and 53 weeks\",\"author\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#articleImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"Leonid Mamchenkov\"},\"datePublished\":\"2010-02-10T23:11:57+02:00\",\"dateModified\":\"2010-02-12T00:16:52+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":6,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#webpage\"},\"articleSection\":\"All, Programming, PHP, tips\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/programming\\\/#listItem\",\"name\":\"Programming\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/programming\\\/#listItem\",\"position\":3,\"name\":\"Programming\",\"item\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/programming\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#listItem\",\"name\":\"PHP date() and 53 weeks\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#listItem\",\"position\":4,\"name\":\"PHP date() and 53 weeks\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/programming\\\/#listItem\",\"name\":\"Programming\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#person\",\"name\":\"Leonid Mamchenkov\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"Leonid Mamchenkov\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/#author\",\"url\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/\",\"name\":\"Leonid Mamchenkov\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"Leonid Mamchenkov\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#webpage\",\"url\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/\",\"name\":\"PHP date() and 53 weeks - Leonid Mamchenkov\",\"description\":\"Let's say you have a bunch of statistical data. And all that data is date-related. And let's say want to display that data on a chart, a weekly average or something along those lines. One of the ways for you to place the value into the proper week would be something like this: [php] $week\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2010\\\/02\\\/10\\\/php-date-and-53-weeks\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/#author\"},\"datePublished\":\"2010-02-10T23:11:57+02:00\",\"dateModified\":\"2010-02-12T00:16:52+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#website\",\"url\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/\",\"name\":\"Blog of Leonid Mamchenkov\",\"description\":\"Life, universe, and everything else\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"PHP date() and 53 weeks - Leonid Mamchenkov","description":"Let's say you have a bunch of statistical data. And all that data is date-related. And let's say want to display that data on a chart, a weekly average or something along those lines. One of the ways for you to place the value into the proper week would be something like this: [php] $week","canonical_url":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"google-site-verification":"VHvdD0_usx1_4DzKy_QCVcICVgX2EgA2ybELT-wl7kQ","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#blogposting","name":"PHP date() and 53 weeks - Leonid Mamchenkov","headline":"PHP date() and 53 weeks","author":{"@id":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/#author"},"publisher":{"@id":"https:\/\/mamchenkov.net\/wordpress\/#person"},"image":{"@type":"ImageObject","@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#articleImage","url":"https:\/\/secure.gravatar.com\/avatar\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g","width":96,"height":96,"caption":"Leonid Mamchenkov"},"datePublished":"2010-02-10T23:11:57+02:00","dateModified":"2010-02-12T00:16:52+02:00","inLanguage":"en-US","commentCount":6,"mainEntityOfPage":{"@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#webpage"},"isPartOf":{"@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#webpage"},"articleSection":"All, Programming, PHP, tips"},{"@type":"BreadcrumbList","@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress#listItem","position":1,"name":"Home","item":"https:\/\/mamchenkov.net\/wordpress","nextItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/#listItem","name":"Programming"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/#listItem","position":3,"name":"Programming","item":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#listItem","name":"PHP date() and 53 weeks"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#listItem","position":4,"name":"PHP date() and 53 weeks","previousItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/#listItem","name":"Programming"}}]},{"@type":"Person","@id":"https:\/\/mamchenkov.net\/wordpress\/#person","name":"Leonid Mamchenkov","image":{"@type":"ImageObject","@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g","width":96,"height":96,"caption":"Leonid Mamchenkov"}},{"@type":"Person","@id":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/#author","url":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/","name":"Leonid Mamchenkov","image":{"@type":"ImageObject","@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g","width":96,"height":96,"caption":"Leonid Mamchenkov"}},{"@type":"WebPage","@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#webpage","url":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/","name":"PHP date() and 53 weeks - Leonid Mamchenkov","description":"Let's say you have a bunch of statistical data. And all that data is date-related. And let's say want to display that data on a chart, a weekly average or something along those lines. One of the ways for you to place the value into the proper week would be something like this: [php] $week","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mamchenkov.net\/wordpress\/#website"},"breadcrumb":{"@id":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/#breadcrumblist"},"author":{"@id":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/#author"},"creator":{"@id":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/#author"},"datePublished":"2010-02-10T23:11:57+02:00","dateModified":"2010-02-12T00:16:52+02:00"},{"@type":"WebSite","@id":"https:\/\/mamchenkov.net\/wordpress\/#website","url":"https:\/\/mamchenkov.net\/wordpress\/","name":"Blog of Leonid Mamchenkov","description":"Life, universe, and everything else","inLanguage":"en-US","publisher":{"@id":"https:\/\/mamchenkov.net\/wordpress\/#person"}}]},"og:locale":"en_US","og:site_name":"Leonid Mamchenkov - Life, universe, and everything else","og:type":"article","og:title":"PHP date() and 53 weeks - Leonid Mamchenkov","og:description":"Let's say you have a bunch of statistical data. And all that data is date-related. And let's say want to display that data on a chart, a weekly average or something along those lines. One of the ways for you to place the value into the proper week would be something like this: [php] $week","og:url":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/","og:image":"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg","og:image:secure_url":"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg","og:image:width":1024,"og:image:height":1024,"article:published_time":"2010-02-10T21:11:57+00:00","article:modified_time":"2010-02-11T22:16:52+00:00","article:publisher":"https:\/\/www.facebook.com\/MamchenkovBlog","twitter:card":"summary_large_image","twitter:site":"@mamchenkov","twitter:title":"PHP date() and 53 weeks - Leonid Mamchenkov","twitter:description":"Let's say you have a bunch of statistical data. And all that data is date-related. And let's say want to display that data on a chart, a weekly average or something along those lines. One of the ways for you to place the value into the proper week would be something like this: [php] $week","twitter:creator":"@mamchenkov","twitter:image":"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg"},"aioseo_meta_data":{"post_id":"12125","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2023-07-19 08:39:09","updated":"2026-01-15 04:34:02","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/mamchenkov.net\/wordpress\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/\" title=\"Programming\">Programming<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tPHP date() and 53 weeks\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/mamchenkov.net\/wordpress"},{"label":"Technology","link":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/"},{"label":"Programming","link":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/"},{"label":"PHP date() and 53 weeks","link":"https:\/\/mamchenkov.net\/wordpress\/2010\/02\/10\/php-date-and-53-weeks\/"}],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":28653,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/06\/30\/php-jsonq-a-simple-elegant-php-package-to-query-over-any-type-of-json-data\/","url_meta":{"origin":12125,"position":0},"title":"php-jsonq &#8211; a simple, elegant PHP package to query over any type of JSON data","author":"Leonid Mamchenkov","date":"June 30, 2018","format":false,"excerpt":"php-jsonq provides an easy, yet powerful way to build queries for any JSON data (or PHP data structures for that matter, which are a step away).\u00a0 This has a variety of useful applications - data migration, API response filtering, complex configurations manipulation, and so on, and so forth.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":25030,"url":"https:\/\/mamchenkov.net\/wordpress\/2015\/12\/10\/weird-php-error-output-bug\/","url_meta":{"origin":12125,"position":1},"title":"Weird PHP error output bug","author":"Leonid Mamchenkov","date":"December 10, 2015","format":false,"excerpt":"We came across this PHP bug at work today. \u00a0But before you go and read it, let me show you a use case. \u00a0See, if you can spot the problem. We had a cron job script which looked something like this (shortened for clarity): [code lang=\"bash\"] #!\/bin\/bash # ... a\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":21719,"url":"https:\/\/mamchenkov.net\/wordpress\/2014\/04\/28\/faker-is-a-php-library-that-generates-fake-data\/","url_meta":{"origin":12125,"position":2},"title":"Faker is a PHP library that generates fake data","author":"Leonid Mamchenkov","date":"April 28, 2014","format":"link","excerpt":"Faker is a PHP library that generates fake data","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":21465,"url":"https:\/\/mamchenkov.net\/wordpress\/2014\/04\/09\/php-debug-bar\/","url_meta":{"origin":12125,"position":3},"title":"PHP Debug Bar","author":"Leonid Mamchenkov","date":"April 9, 2014","format":"link","excerpt":"PHP Debug Bar The DebugBar integrates easily in any projects and can display profiling data from any part of your application. It comes built-in with data collectors for standard PHP features and popular projects.","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":29035,"url":"https:\/\/mamchenkov.net\/wordpress\/2018\/11\/27\/avoid-complex-arrays-in-php\/","url_meta":{"origin":12125,"position":4},"title":"Avoid complex arrays in PHP","author":"Leonid Mamchenkov","date":"November 27, 2018","format":false,"excerpt":"Now that PHP 7+ sorted out a whole bunch of problems with type-hinting of parameters, return values, variables and properties, we turn our attention to somewhat deeper issues. Array is a native citizen in PHP.\u00a0 Arrays are very convenient and are widely used.\u00a0 However, if you stop and think about\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":18605,"url":"https:\/\/mamchenkov.net\/wordpress\/2013\/09\/13\/beautifying-phps-json_encode-output\/","url_meta":{"origin":12125,"position":5},"title":"Beautifying PHP&#8217;s json_encode() output","author":"Leonid Mamchenkov","date":"September 13, 2013","format":false,"excerpt":"I've been working a bit more with PHP and JSON recently and one of the things that annoyed me quite a bit was the single line output of the json_encode() function. \u00a0Here is an example: [code lang=\"php\"] <?php $data = array( 'foo' => 'bar', 'bar' => 'qux', 'blah' => 'blah',\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/12125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=12125"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/12125\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=12125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=12125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=12125"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=12125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}