Results 1 to 8 of 8

Thread: Last Wednesday's Date?

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Last Wednesday's Date?

    I want to be able to find out the date for last Wednesday. If today is Wednesday, then I want to get that date. So far I have:

    Code:
    if (date('D') == 'Wed') {
        echo date('Y-m-d');
    } else {
        //$last = 
        echo "Last Wednesday was $last";
    }
    Any ideas?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Would I have to do it like this:

    Code:
    if (date('D') == 'Wed') {
        echo date('Y-m-d');
    } else {           
        switch (date('D')) {
            case 'Thu':
                echo date('Y-m-d', strtotime('-1 day'));
                break;
        }
    }
    Or is there an easier way?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I suppose using strtotime ("last Wednesday") would be easier
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    could also do somethign like this: I think this will work


    $dy = date("D");
    $mn = date("m");
    $yr = date("Y")
    $lastweek = strftime("%d", mktime(0,0,0,0,$dy-7,0));

  5. #5

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    D-7 will give me a week ago? What if today's thursday? Right...?

    And I think strtotime("Last Wednesday") is about as simple as it gets.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    hehe good point.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    strtotime rules.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    strtotime rules.
    Indeed. I find it more and more useful everyday.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width