I have a start date like 07/18/2014, a end date like 07/24/2014, and a period date: every 2 days. So every 2 days starting by 07/18 i warn the user that something have to do, if is not the right day i warn the user about how left days remaining to the next warning. How can i do? And if add also time and a period of every 2 hours?
I thought about store first all the dates warning in an array [07-18/2014, 07-20-2014, 07-22-2014, 07/24/2014]
My code is the following but it does not work. Maybe it is not correct like I use strtotime
$endg = strtotime ( "+". $dataupto . " days", strtotime ( $row['startdate'] ) ) ;
$endg = date ( 'Y/m/d' , $endg );
$endgSTR = strtotime($endg);
$tempg = strtotime($row['startdate']);
while( $tempg < $endgSTR){
$arraymonitor[] = strtotime( date($tempgdate ) );
$tempg = $tempg + (strtotime ( " +1 days", $tempg ) );
$arraymonitor[] = $tempg;
echo "</br> tempg in while:";
echo $tempg . " ";
echo "</br> tempg in while 2:";
echo date ( 'Y/m/d' , $tempg ) . "<br/>";
}
I accept also other suggestions!
UPDATE SOLUTION
header( "content-type: text-plain" );
function dayDiff($start, $end){
$timeleft = $end - $start;
$daysleft = round((($timeleft/24)/60)/60);
return $daysleft;
}
function testWarning($today, $end, $delay){
$endDate = strtotime($end);
$warningDate = $endDate;
$todayDate = strtotime($today);
if( $todayDate == $warningDate ){
echo "Oggi c'è un controllo da fare";
}elseif( $todayDate < $warningDate ){
echo "Miss " . dayDiff($todayDate, $warningDate) . " days";
}else{
echo "warning was " . abs(dayDiff($todayDate, $warningDate)) . " giorni fa";
}
echo"\n";
}
$ardata = [07/18/2014, 07/20/2014, 07/22/2014, 07/24/2014];
$today3 = "07/21/2014"; // the day after warning
testWarning( $today3, $end, $delay );
$diffmin = 1000;
for ($i = 0 ; $i<= count($ardata)-1; $i++){
//print_r($ardata);
echo "</br> </br> ardata ";
echo $ardata[$i];
$dataseq = date ( 'm/d/Y' , strtotime($ardata[$i]) );
$diffdata = dayDiff( strtotime($today3), strtotime($dataseq) );
echo "</br></br> DIFFDATA: ";
echo $diffdata;
echo " DIFFMIN ";
echo $diffmin;
if ($diffdata > 0){ // avoiding days before today
if ($diffdata < $diffmin){
$diffmin = $diffdata;
$nextdata = $ardata[$i];
}else{
if ($diffdata == -1){
echo "error array empty";
$nextdata = $today3;
}
}
}else{
echo "monitorterminato";
$nextdata = -1;
}
}
if ($nextdata != -1){
if ($diffmin == 0){ // giorno di oggi quindi avviso
echo "warning WARNING </br> </br>";
}else if ($diffmin > 0 ){
echo " oggi ". $today3." prossimo:". $nextdata. " </br></br>";
testWarning( $today3, $nextdata, $delay );
}else{
// caso errato
echo " </br> </br> ERRORE nel calcolo non può essere negativo";
}
}