Results 1 to 5 of 5

 

Thread: strtotime -unexpected results

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Feb 2006
    Location
    Gillingham
    Posts
    510
    Thanks
    0
    Thanked 4 Times in 1 Post


    I was trying to get a list of monthends over the previous year using strtotime ("last month").

    So I tried this:
    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>";
    }
    ?>
    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.

    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
    The most difficult to understand is from september onwards! PHP regards last september as 29/09/2006?????
    They came for my 404 and I said nothing

  2. #2
    Tom
    Registered User

    Status
    Offline
    Join Date
    May 2005
    Posts
    238
    Thanks
    0
    Thanked 4 Times in 4 Posts
    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

  3. #3
    Driving to win

    Status
    Offline
    Join Date
    Aug 2003
    Location
    If I'm not at home, I'm in hospital
    Posts
    7,370
    Thanks
    7
    Thanked 16 Times in 11 Posts
    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.

  4. #4
    Registered User

    Status
    Offline
    Join Date
    Feb 2006
    Location
    Gillingham
    Posts
    510
    Thanks
    0
    Thanked 4 Times in 1 Post
    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

  5. #5
    Driving to win

    Status
    Offline
    Join Date
    Aug 2003
    Location
    If I'm not at home, I'm in hospital
    Posts
    7,370
    Thanks
    7
    Thanked 16 Times in 11 Posts
    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.



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Google Sued for Low Rankings
    By Another Media in forum Affiliate Marketing Lounge
    Replies: 66
    Last Post: 26-04-07, 11:57 PM
  2. google to expand into CPA
    By betterHalf in forum Affiliate Marketing Lounge
    Replies: 23
    Last Post: 30-06-06, 12:53 PM
  3. ASOS Audit Results
    By jesss1 in forum Affiliate Marketing Lounge
    Replies: 13
    Last Post: 27-02-04, 10:14 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2