Isn't it just one day short on each month?
I was trying to get a list of monthends over the previous year using strtotime ("last month").
So I tried this:
I got some surprising results! I could have accepted the first day month or the last day of the previous month, but the results I got were a day before the end of the month.PHP Code:<?php
$montharray=array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
foreach ($montharray as $key=>$value){
$showdate=date("Y-m-d H:i:s", strtotime("last ".$value));
echo $showdate."<br>";
}
?>
The most difficult to understand is from september onwards! PHP regards last september as 29/09/2006?????2005-12-30 00:00:00
2006-01-30 00:00:00
2006-02-27 00:00:00
2006-03-30 00:00:00
2006-04-29 00:00:00
2006-05-30 00:00:00
2006-06-29 00:00:00
2006-07-30 00:00:00
2006-08-30 00:00:00
2006-09-29 00:00:00
2006-10-30 00:00:00
2006-11-29 00:00:00
They came for my 404 and I said nothing
Isn't it just one day short on each month?
Websites for Sale - Browse sites for sale and place an ad for free.
Social Shopping - Join our affiliate program
The problem is because strtotime treats every month as being 30 days.
It is a known bug in strtotime.
You are also misinterpreting what it means by last - it does not mean the last day of the month, it means previous - i.e last monday = monday last week.
Never argue with idiots. They just drag you down to their level and then beat you with their experience.
If ignorance is bliss then some of the people I know must be orgasmic.
Hi keith
I understand the concept of last month.
But "last Sep" gives 2006-09-29 00:00:00 I would say that is this or even next september I would have expected 2005-09-29 to be consistent.
Bob
They came for my 404 and I said nothing
Hi Bob
That's true - looks like it's a function with more than a few quirks!!
Never argue with idiots. They just drag you down to their level and then beat you with their experience.
If ignorance is bliss then some of the people I know must be orgasmic.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks