How would I get the dates from the previous wednesday to the last tuesday?

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

    #1

    How would I get the dates from the previous wednesday to the last tuesday?

    Hey I need to be able to get the dates from last wednesday to the past
    tuesday on thursday or friday every week. How would I do that?

    For example:
    m t W TH F
    M T w th f

    I would need the dates of the CAPITAL W and T when I run the script
    from the last th or f

    So if today is 2006-1-19 I would need 2006-1-11 and 2006-1-17

    Thanks for the help.

  • Kimmo Laine

    #2
    Re: How would I get the dates from the previous wednesday to the last tuesday?

    "rf" <ryanf@twcny.rr .com> kirjoitti
    viestissä:11375 15000.637963.32 3170@o13g2000cw o.googlegroups. com...[color=blue]
    > Hey I need to be able to get the dates from last wednesday to the past
    > tuesday on thursday or friday every week. How would I do that?
    >
    > For example:
    > m t W TH F
    > M T w th f
    >
    > I would need the dates of the CAPITAL W and T when I run the script
    > from the last th or f
    >
    > So if today is 2006-1-19 I would need 2006-1-11 and 2006-1-17
    >[/color]


    As usually, there's more than one way to do it, here's one:
    First find out what was last tuesday, easy as pie with strtotime:

    $last_tuesday = strtotime('last tuesday');

    After that you can get all the dates with the same method (using
    $last_tuesday as a reference point instead of today so we don't get this
    weeks "last wednesday" if it happens to be friday, but "last wednesday"
    counting from last tuesday).

    $last_monday = strtotime('last monday', $last_tuesday);
    $last_friday = strtotime('last friday', $last_tuesday);
    $last_thursday = strtotime('last thursday', $last_tuesday);
    $last_wednesday = strtotime('last wednesday', $last_tuesday);

    Now you can convert them to human readable formats using date:
    echo date('Y-m-d', $last_monday); // for example

    --
    SETI @ Home - Donate your cpu's idle time to science.
    Further reading at <http://setiweb.ssl.ber keley.edu/>
    Kimmo Laine <antaatulla.sik anautaa@gmail.c om.NOSPAM.inval id>


    Comment

    • rf

      #3
      Re: How would I get the dates from the previous wednesday to the last tuesday?

      thanks I never knew about strtotime. Its a very cool function. Thanks
      for pointing it out to me.

      Comment

      Working...