PHP Invoices change start day of the week -2 days

62 Views Asked by At

I have a question im busy with an invoice system and have the following problem: We want to send the invoices every saterday and each week.

So our week is from saterday till friday.

Now is our output like this:

Order:3869
Weeknr:2017-07
Weektime:2017-02-17 16:11:54
EndDate:2017-02-18

Weektime String:1487347914
EndDate String:1487376000

Order:3874
Weeknr:2017-07
Weektime:2017-02-19 14:52:57
EndDate:2017-02-18

Weektime String:1487515977
EndDate String:1487376000

Here you see Order: 3874, this needs to be Weeknr: 2017-08

This is my loop:

foreach( $orders as $order){
    if($order->post->post_parent != 0){
        $endDate = strtotime(date('Y-m-d',strtotime('last saturday')));
        $week = date('Y-W', strtotime($order->post->post_date));
        $weektime = strtotime($order->post->post_date);

if($weektime > $eindDatum){
                continue;
            }
    }

Now i can't find how i can see if our week starts at monday in PHP, if thats true how can i change weektime -2 days.

Sorry for my poor explanation in bad english but I hope someone can help me

O this is my pre of the orders like the example:

    echo '<pre>';
        echo 'Order:'.print_r($order->post->ID,true).'<br>';
        echo 'Weeknr:'.print_r($week,true).'<br>';
        echo 'Weektime:'.print_r($order->post->post_date,true).'<br>';
        echo 'EindDatum:'.print_r(date('Y-m-d',strtotime('last saturday')),true).'<br><br>';
        echo 'Weektime String:'.print_r($weektime,true).'<br>';
        echo 'EindDatum String:'.print_r($eindDatum,true).'<br>';
    echo '</pre>';
1

There are 1 best solutions below

2
gmourier On

You can use php DateTime object in association with modify method to move a portion of time on a date.

Example

$date = new DateTime('2006-12-12'); $date->modify('-2 day');