greens85 Posted March 14, 2011 Share Posted March 14, 2011 Hi all, I am trying to figure out how to calculate 5 working days prior to a given date. I have done some googling but can only see examples of how to add 5 working days onto a date, such as this: $holidayList = array(); $j = $i = 1; while($i <= 5) { $day = strftime("%A",strtotime("+$j day")); $tmp = strftime("%d-%m-%Y",strtotime("+$j day")); if($day != "Sunday" and $day != "Saturday" and !in_array($tmp, $holidayList)) { $i = $i + 1; $j = $j + 1; } else $j = $j + 1; } $j = $j -1; echo strftime("%A, %d-%m-%Y",strtotime("+$j day")); Does anyone know how to calculate 5 working days prior to a date? Many thanks, Greens85 Quote Link to comment https://forums.phpfreaks.com/topic/230601-calculate-5-working-days-prior-to-a-give-date/ Share on other sites More sharing options...
Zane Posted March 14, 2011 Share Posted March 14, 2011 did you try strtotime("-$j day") Quote Link to comment https://forums.phpfreaks.com/topic/230601-calculate-5-working-days-prior-to-a-give-date/#findComment-1187375 Share on other sites More sharing options...
greens85 Posted March 14, 2011 Author Share Posted March 14, 2011 Hi, Many thanks for your response. I didn't try that but now I have it works perfectly.. I just need to figure out which part holds todays date now as I don't want to subtract from that but rather I date I have stored in a database. I assume this is perfectly doable with the provided code? Quote Link to comment https://forums.phpfreaks.com/topic/230601-calculate-5-working-days-prior-to-a-give-date/#findComment-1187376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.