Ok, this is simply everything I need help with:

I want to get the first date of current week in d-m-Y format.
I've tried with Date(), mkdate() ans strotime, but haven't succeeded yet. I'm rather new to php...

Any help would be appreciated! 😃

[Edit]
One solution would be to get current day (ie wednesday) and then calculate current date -2, but there must be a better way to do this [/Edit]

    First you would write a function like this. Note that this function treats sunday as the first day of the week and not monday as in your post, but that could be fixed pretty easily.

    <?php
    function first_day_of_week($date = '') {
        if($date == '') $date = time();
    
    $day = date('w',$date);
    
    //the number of seconds since the most recent sunday.
    $offset = $day * 86400;
    
    $start_of_week = $date - $offset;
    return $start_of_week;
    } //end first_day_of_week
    ?>

    The you would call it like this

    <?php
        $time = first_day_of_week();
        echo "Today is " . date('d-m-Y') . " Sunday was " . date('d-m-Y',$time);
    ?>

      Thanks for the fast reply, it works perfectly!!

        Write a Reply...