SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Texas
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date math problem - getdate()

    Hello all.

    I've got a problem that's almost certainly simple to fix, but I can't seem to see the solution. What I'm trying to do is subtract 2 months from the system date and I can't seem to get it to work. Here's the code I've got:

    $today = getdate();
    $unixdate = $today[0];
    $delete_date = $unixdate - (60 * 60 * 24 * 60); // subtract 60 days (in seconds)
    $delete_month = $delete_date['mon'];
    echo"Delete_month = $delete_month<br>";

    When this runs, the variable $delete_month doesn't have a value stored in it.

    I'd apprecaite any help on this. Thanks all!
    CS

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think that you should be able to solve it using strtotime.

    PHP Code:
    $delete_month date('Y-m-d'strtotime('-2 months')); 
    Yours, Erik.


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
  •