php script working every friday
Domanda
I have this script that is working every day between 2 hours. Now, I have 2 questions: 1) how do I make it work only every friday, not all days? 2) how do I use minutes to m code? $hour:$min > 8:15 is not working
<?php
$hour = date('G');
if ($hour >= 8 && $hour <= 10) {
include('facut_mine2.php');
}
?>
Thanks!
Soluzione
use date('w')
to get weekday
<?php
$start = strtotime('8:15');
$end = strtotime('9:45');
if(date('w') == 5){ // day 5 = Friday
$timenow = date('U');
if ($timenow >= $start && $timenow <= $end) {
include('facut_mine2.php');
}
}
?>
Altri suggerimenti
<?php
$hour = date('G');
$day = date('w');
if ($day == 5 && $hour >= 8 && $hour <= 10) {
include('facut_mine2.php');
}
?>
by using D parameter in date() function you can retrieve the current week day:
$today = date('D');// $today = 'Wed'
and for minute you can again use date() function with i
$current_min = date('i');
if(date('D') == 'Fri') {
$hourMin = date('H:i');
if ($hourMin >= '08:15' && $hourMin <= '10:00') {
include('facut_mine2.php');
}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow