PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Lorna Mitchell's Blog: Getting Dates from Week Numbers in PHP

Note: This article was originally published at PHPDeveloper on 23 March 2011.
PHPDeveloper

Lorna Mitchell has a quick handy post to his blog today showing how you can grab the date (a timestamp) from the week number of the year.

Recently I've been building a little project that pulls data from Google Analytics and shows your web statistics in a simple form. One thing I wanted to do was show the data for a quarter, but graphing by day is too chaotic and graphing by month only gives three points, so I wanted to graph by week. This was fine but the data returned by Analytics only gives me the week numbers, and since this project is aimed at demystifying web stats for normal people, it really needs normal dates on it!

Thanks to the DateTime functionality built in to PHP and the setIsoDate function, pulling the date back is a simple single call away. She also points out the reverse - using the "W" in a date call to return the week.