Take the 2-minute tour ×

I'm trying to find the nth day of the month in a timestamp like so:

$day = 15;

$date = new DateTime('@' . $timestamp);
$date->modify($day . ' day of current month');

This generates an error:

Warning: DateTime::modify(): Failed to parse time string (15 day of current month) at position 7

I've also tried "day 15 of current month" and that does not work.

How can I modify my "modify" to find the nth day of the current month in the timestamp?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

First retrieve the first day of the month, then add the number of days you want.

$date = new DateTime('first day of ' . date("Y-m-d", $timestamp));
$date->modify('+' . ($day-1) . 'days');
share|improve this answer
Yea, I figured as much. I was just hoping to save a line of code. :) –  doremi Aug 30 '12 at 20:46

You can use php's date() formatting capabilities with a hard-set "day" value (adapt as necessary):

$timestamp = time();
$format = date('Y-15-M', $timestamp);
$fifteenth = strtotime($format);
echo "15th was a " . date("D", $fifteenth) . "\n";
share|improve this answer

Your Answer


