SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Some Date-related function questions

    Why, when I set $year to 2008, is it setting $year to 2007 after I put it through some functions?

    PHP Code:
    $year "2008";
    echo 
    $year."<br />";
    $year strtotime($year);
    echo 
    date("Y"$year);
    $prev_year date("Y"strtotime("-1 Year"$year)); 
    I'm trying to draw the previous year from whatever is passed as the current year, but I keep getting 2006...

    Thanks for any help.
    No, I REALLY dislike having to use Joomla.

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code PHP:
    date("Y", strtotime("-1 year", mktime ( 0,0,0,1,1,2003)))

    Unfortunately:

    The number of the year, may be a two or four digit value, with values between 0-69 mapping to 2000-2069 and 70-100 to 1970-2000. On systems where time_t is a 32bit signed integer, as most common today, the valid range for year is somewhere between 1901 and 2038, although this limitation is overcome as of PHP 5.1.0.
    So:

    Code PHP:
    date("Y", strtotime("-1 year", mktime ( 0,0,0,1,1,2093)))

    Will give you the invalid date 1968 year on versions of PHP previous to 5.1.0


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
  •