ale1981 Posted June 20, 2007 Share Posted June 20, 2007 Hi, I need to setup a script to run on the FIRST WORKING DAY of each month. I will have the script running as a cron. I was thinking the easiest way of doing this would be to have a bit of php inside the script that detects to see if the day is the first working day of the month and just run the cron every day? Any ideas on how I could script that? Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/ Share on other sites More sharing options...
Dragen Posted June 20, 2007 Share Posted June 20, 2007 you'd probably need an array of the first days, then compare that with the current date. Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278408 Share on other sites More sharing options...
ale1981 Posted June 20, 2007 Author Share Posted June 20, 2007 Thanks for your reply. Never thought of doing it that way, so I could have an array of all the dates that I want the script to run and check the array to see if the date matches? $go_date = array(); $go_date = '01-01-07', '01-02-07', 01-03-07' ...... How would i then search through that array to find if todays day matches it? Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278416 Share on other sites More sharing options...
ale1981 Posted June 20, 2007 Author Share Posted June 20, 2007 Sorry, searched at uk.php.net and found my answer; http://uk.php.net/function.in-array Thanks again for your help. Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278419 Share on other sites More sharing options...
komquat Posted June 20, 2007 Share Posted June 20, 2007 By working day, do you mean Mon- Fri? If so, why not get the day of week from the date function and check that against the first working day. $day_num = date(j); if ($day_num <= 3) { $day_name = date(l); //lower case 'L' if (($day_name <> Saturday) or ($day_name <> 'Sunday')) { echo "First Working day"; } else { echo "Weekend"; } } Why not someting like that Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278420 Share on other sites More sharing options...
Dragen Posted June 20, 2007 Share Posted June 20, 2007 <?php $go_date = array('01-01-07', '01-02-07', '01-03-07'); if(array_search(date(m-d-y), $go_date) === true){ // todays date is a working day. give it a cookie }else{ // todays date is not a first working day. bad day! } ?> something like that. Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278421 Share on other sites More sharing options...
ale1981 Posted June 20, 2007 Author Share Posted June 20, 2007 By working day, do you mean Mon- Fri? If so, why not get the day of week from the date function and check that against the first working day. $day_num = date(j); if ($day_num <= 3) { $day_name = date(l); //lower case 'L' if (($day_name <> Saturday) or ($day_name <> 'Sunday')) { echo "First Working day"; } else { echo "Weekend"; } } Why not someting like that Unfortunately this way would not take into account bank holidays / xmas periods etc? Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278426 Share on other sites More sharing options...
ale1981 Posted June 20, 2007 Author Share Posted June 20, 2007 <?php $go_date = array('01-01-07', '01-02-07', '01-03-07'); if(array_search(date(m-d-y), $go_date) === true){ // todays date is a working day. give it a cookie }else{ // todays date is not a first working day. bad day! } ?> something like that. I think this is the best way? Here is what I had, does in_array work slower than array_search? $tday = date('d-m'); print($tday); $workingday = array('03-01','01-02','01-03','02-04','01-05','01-06','02-07','01-08','03-09','01-10','01-11','03-12'); if (in_array($tday, $workingday)) { echo 'TODAY IS THE FIRST WORKING DAY'; } else { echo 'TODAY IS NOT THE FIRST WORKING DAY'; } Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278427 Share on other sites More sharing options...
Dragen Posted June 20, 2007 Share Posted June 20, 2007 does in_array work slower than array_search? To be honest I don't know what the differende is. They both seem to do the same thing. I think either should work. Your code looks fine. perhaps someone else could clarify the difference between in_array and array_search? Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278444 Share on other sites More sharing options...
GingerRobot Posted June 20, 2007 Share Posted June 20, 2007 Well the manul explains it : array_seach returns the key of the value found if it is successful - looks like thats about the only differance. So if you needed to do something with the key or value when you find it, you'd use array_search. If you are simply looking for existance, you'd use in_array. Quote Link to comment https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278531 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.