Using day number for date manipulation in PHP

October 19, 2011

I needed to take a day number of the year and be able to manipulate that to get other dates associated to it. Let’s take today, October 19th. This is the 292nd day of the year. We can convert this into Unix seconds:

$seconds = date('U',strtotime(date('Y').'-01-01 +'.(292-1).' days'));

As you can see it isn’t a completely obvious solution but it works as needed. Now since we have the timestamp, we could get the Monday before the 180th day.

$seconds = date('U',strtotime(date('Y').'-01-01 +'.(180-1).' days'));
$week_begins = date('Y-m-d', strtotime( 'Last Monday', $seconds));


Stay in Touch!

Stay in Touch!
Solutions Architecture

browse through our blog articles

Blog Archive