PHP subtracting a week from two existing date variables -


php 7.1.7

i have custom work processing week runs saturday through friday. code below, i'm selecting current processing week $current_date '08/25/2017' , returns range of '08/19/2017' (saturday) '08/25/2017' (friday).

what i'm trying previous work processing week. '08/19/2017' selected, should '08/12/2017' through '08/18/2017'.

i'm confused why, when i'm subtracting 1 week $saturday , $friday dates, new 'previous working week' variables off.

the output of php is:

this reporting week: 08/19/2017 08/25/2017

previous reporting week: 12/31/1969 12/31/1969

<?php #------------ working ------------------------- $current_date = "08/25/2017";  if(date("l", strtotime($current_date)) == "saturday"){     $saturday = strtotime($current_date); }else{     $saturday = strtotime($current_date . " previous saturday"); } $friday =  strtotime(date("m/d/y", $saturday) . " next friday");     echo "this reporting week:&nbsp;" . date("m/d/y", $saturday) . " " . date("m/d/y", $friday) . "<br/>";    echo "<br/><br/>"   ;  #------------ not working ---------------------- #not working $previous_week_friday = strtotime('-1 week', strtotime($friday)); $previous_week_friday = date("m/d/y", $previous_week_friday);  $previous_week_saturday = strtotime('-1 week', strtotime($saturday)); $previous_week_saturday = date("m/d/y", $previous_week_saturday);  echo "previous reporting week:&nbsp;" . date("m/d/y", $previous_week_friday) . " " . date("m/d/y", $previous_week_saturday) . "<br/>";    echo "<br/><br/>"    

?>

thanks help.

hello again :-)

well $friday , $saturday integer in unix time have subtract 1 week in seconds. (60 x 60 x 24 x 7).

//#------------ working ------------------------- $current_date = "08/25/2017";  if(date("l", strtotime($current_date)) == "saturday"){     $saturday = strtotime($current_date); }else{     $saturday = strtotime($current_date . " previous saturday"); } $friday =  strtotime(date("m/d/y", $saturday) . " next friday");     echo "this reporting week:&nbsp;" . date("m/d/y", $saturday) . " " . date("m/d/y", $friday) . "<br/>";    echo "<br/><br/>\n"   ;  //#------------ it's working ----------------------  $previous_week_friday = date("m/d/y", $friday-3600*24*7); $previous_week_saturday = date("m/d/y", $saturday-3600*24*7);  echo "previous reporting week:&nbsp;" . $previous_week_friday . " " . $previous_week_saturday . "<br/>";    echo "<br/><br/>"; 

https://3v4l.org/0gj40


the reason output because try use strtotime on unix value.
name of function says, "string time".
unix value not string, it's integer. fails , becomes 0.
0 used in date function , 1970.
, or server west of gmt negative value due timezone 1969 ....


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -