CanMan2004 Posted January 29, 2007 Share Posted January 29, 2007 Hi allI currently print on my page, todays date, the code I use is[code]<?php $date = date('Y,m,d'); ?[/code]How can you get php date to display the date in 3 days time, but skipping weekends, so if it was Friday the 5th, it would show Wednesday the 10th, but if it was Monday the 1st, it would show Thursday the 5th.Does that make sense?I am coding something, I just want other people suggestions as my code is long and doesnt always work out correct.Any help would be fabCheers in advanceDave Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 29, 2007 Share Posted January 29, 2007 [code]<?php //sounds challenging :P$date = strtotime($date);$week = date('D', $date);if ($week == "Thu" or $week == "Fri") {$date = $date + 432000;}// since thu and fri are special caseelse {$date = $date + 259200;}//rest are fine?>[/code]but it doesnt consider input values of Sat and Sun, since they are not the results of your output as well. so only works through inputs of mon-fritook me a while to think :PTed Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 29, 2007 Share Posted January 29, 2007 sorry... forgot wed....[code]<?php //sounds challenging :P$date = strtotime($date);$week = date('D', $date);if ($week == "Wed" or $week == "Thu" or $week == "Fri") {$date = $date + 432000;}// since wed, thu and fri are special caseelse {$date = $date + 259200;}//rest are fine?>[/code]I think that would work.... Quote Link to comment Share on other sites More sharing options...
CanMan2004 Posted January 29, 2007 Author Share Posted January 29, 2007 Hi TedWhen I use that, I put at the bottomprint $date;and it returns 1170288000Any ideas why? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 That's a timestamp, you need to then use the date() function on it.Ted, I'm actually impressed. I didn't check it very thoroughly, but looks good. Nice job. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 29, 2007 Share Posted January 29, 2007 if you need a clue of what i am trying to do here:Since you want to skip the weekends, therefore, only concerns Wed, Thu, and Fri.Others such as Mon and Tue only go up to Thu and Fri.So for Wed, Thu and Fri, I add 5 days instead of three days, therefore, the two days (sat and sun) of the weekends are counted into the addition.Does that make it clear?Ted Quote Link to comment Share on other sites More sharing options...
CanMan2004 Posted January 29, 2007 Author Share Posted January 29, 2007 So what code would I use to convert it into a date() Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 29, 2007 Share Posted January 29, 2007 thanks jesirose, i wonder if thats a irony or compliment,CanMan2004, do this:$date = date('M d, Y h:i A', $date);// this is my fav. format personally.check this to optimize yours: http://uk.php.net/dateTed Quote Link to comment Share on other sites More sharing options...
CanMan2004 Posted January 29, 2007 Author Share Posted January 29, 2007 Found itprint strftime("%c",$date) Quote Link to comment Share on other sites More sharing options...
obsidian Posted January 29, 2007 Share Posted January 29, 2007 I would try something like this (again, maybe not the most optimal, but at least it's reliable):[code]<?phpfunction getThreeDays($date) { $day = 60 * 60 * 24; $newDate = strtotime($date . " + 3 days"); // Sunday is the result, add one day if (date('w', $newDate) == 0) $newDate += $day; // Saturday is the result, add two days elseif (date('w', $newDate) == 6) $newDate += (2 * $day); return date('Y-m-d', $newDate);}?>[/code]Tested, and it seems to work well. Feed it a YYYY-MM-DD format, and it returns the same with the correct date. Quote Link to comment Share on other sites More sharing options...
CanMan2004 Posted January 29, 2007 Author Share Posted January 29, 2007 No compaints Ted, you did a fine job and helped out loads, thank you. top man Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 29, 2007 Share Posted January 29, 2007 welcome, my pleasure ;D Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 edit: I'm slow today. Quote Link to comment 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.