current date - 7 dayz?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mr_burns

    current date - 7 dayz?

    hi,
    i am wanting to get the date 7 days ago but wasnt sure how to do it.
    something like:

    $current_date = date("Y-m-d") - [seven days];

    also, i would like to expand this to get the date 3/6 months ago or a
    year ago. any ideas? cheers

    burnsy
  • Tom Thackrey

    #2
    Re: current date - 7 dayz?


    On 7-Oct-2003, bissatch@yahoo. co.uk (mr_burns) wrote:
    [color=blue]
    > i am wanting to get the date 7 days ago but wasnt sure how to do it.
    > something like:
    >
    > $current_date = date("Y-m-d") - [seven days];
    >
    > also, i would like to expand this to get the date 3/6 months ago or a
    > year ago. any ideas? cheers[/color]

    $when = '2003-04-01';
    $dayminus7 = date('Y-m-d',strtotime("$ when -7 day"));
    $dayminus3month s = date('Y-m-d',strtotime("$ when -3 month"));
    $dayminus1year = date('Y-m-d',strtotime("$ when -1 year"));

    You can also use $when = 'now'; for the current date.


    --
    Tom Thackrey

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    • Paulus Magnus

      #3
      Re: current date - 7 dayz?

      "mr_burns" <bissatch@yahoo .co.uk> wrote in message
      news:651c6ea9.0 310071556.252db c75@posting.goo gle.com...[color=blue]
      > hi,
      > i am wanting to get the date 7 days ago but wasnt sure how to do it.
      > something like:
      >
      > $current_date = date("Y-m-d") - [seven days];
      >
      > also, i would like to expand this to get the date 3/6 months ago or a
      > year ago. any ideas? cheers
      >
      > burnsy[/color]

      $date = date ("Y-m-d", time () - (7*86400)); //Last week's time

      Just change the 7 to 91 and 182 for the other two time periods. If you're
      after an accurate 3/6 month period, you'd have to convert today's month into
      a number, subtract 3 from it (or 6). If this month is then less than 1, add
      12 to it and subtract 1 from the year. Stuff all this back in and you'll get
      your date.

      Paulus


      Comment

      • De.Snor

        #4
        Re: current date - 7 dayz?

        On 7 Oct 2003 16:56:51 -0700, bissatch@yahoo. co.uk (mr_burns) wrote:
        [color=blue]
        >hi,
        >i am wanting to get the date 7 days ago but wasnt sure how to do it.
        >something like:
        >
        >$current_dat e = date("Y-m-d") - [seven days];
        >
        >also, i would like to expand this to get the date 3/6 months ago or a
        >year ago. any ideas? cheers
        >[/color]

        PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


        <?php
        // 7 days ago
        $date7daysago = date("Y-m-d", mktime (0, 0, 0, date("m"),
        date("d") - 7, date("Y")));

        // 3 months ago
        $date3monthsago = date("Y-m-d", mktime (0, 0, 0, date("m") - 3,
        date("d"), date("Y")));

        // etcetera...

        ?>

        --
        Greetz,
        De Snor

        Comment

        Working...