# Problem with date() "M" format

**URL:** <https://www.phphelp.com/t/problem-with-date-m-format/18901>\
**Category:** Beginners - Learning PHP\
**Created:** [November 13, 2012, 4:07am UTC](https://www.phphelp.com/t/problem-with-date-m-format/18901 "2012-11-13T04:07:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobM](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@RobM](https://www.phphelp.com/u/RobM)\
**Post date:** [November 13, 2012, 4:07am UTC](https://www.phphelp.com/t/problem-with-date-m-format/18901/1 "2012-11-13T04:07:13Z")

</div>

I’m having the most difficult time getting the date to print May 17th, 2010 with the month (“F”) format being the issue. I’m having to get it to say November (the current month) but if I subtract from that it turns into an integer. Any help would be most appreciated! Thank you!

[php]  
// Display the following date using the date() function: “May 24th, 2010”

$month = date (“F”, time()) - 6;  
$day = date (“D”, time()) + 17;  
$year = date (“Y”, time()) - 2;

echo $month," ", $day ,"th, ", $year;  
[/php]

---

<div class="post-metadata">

**Author:** ![m11](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@m11](https://www.phphelp.com/u/m11)\
**Post date:** [November 13, 2012, 4:50am UTC](https://www.phphelp.com/t/problem-with-date-m-format/18901/2 "2012-11-13T04:50:18Z")

</div>

You should use functions such as mktime() or strtotime() e.g.

[php]  
$month = date(“F”, strtotime("-6 months"));  
var\_dump($month);  
[/php]

Here is another example using mktime()

[php]  
$month = date(“F”, mktime(0, 0, 0, date(‘m’) - 6, date(‘d’), date(‘Y’)));  
var\_dump($month);  
[/php]

---

<div class="post-metadata">

**Author:** ![RobM](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@RobM](https://www.phphelp.com/u/RobM)\
**Post date:** [November 13, 2012, 5:07am UTC](https://www.phphelp.com/t/problem-with-date-m-format/18901/3 "2012-11-13T05:07:36Z")

</div>

Hey thank you for your response.

That does result in the month being illustrated as “May” rather than “-6” which was happening with my code above however why is it that my code results as such? It seems to match the parameters outlined in [php.net](http://php.net)? To test, I used [codepad.org](http://codepad.org) and I came up with the same result

---

<div class="post-metadata">

**Author:** ![m11](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@m11](https://www.phphelp.com/u/m11)\
**Post date:** [November 13, 2012, 5:26am UTC](https://www.phphelp.com/t/problem-with-date-m-format/18901/4 "2012-11-13T05:26:13Z")

</div>

I don’t know what you are referring to on [php.net](http://php.net) but it certainly is not correct. By taking a string “November” and subtracting 6 you are converting the string to an integer (0) which gives you 0 - 6 = -6

---

<div class="post-metadata">

**Author:** ![RobM](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/278dde/32.png) [@RobM](https://www.phphelp.com/u/RobM)\
**Post date:** [November 13, 2012, 5:28am UTC](https://www.phphelp.com/t/problem-with-date-m-format/18901/5 "2012-11-13T05:28:19Z")

</div>

Ahhh, yes. That makes sense. Thank you for explaining the obvious! I’ve been hitting my head with this one for the last few days!
