Jump to content

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/56358-working-days/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278416
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278420
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278426
Share on other sites

<?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';
}

Link to comment
https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278427
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/56358-working-days/#findComment-278531
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.