Skip to content

Instantly share code, notes, and snippets.

@binarykore
Last active March 3, 2022 15:43
Show Gist options
  • Save binarykore/5ca7d3b6bef9eddc9e7e0780ecda1488 to your computer and use it in GitHub Desktop.
Save binarykore/5ca7d3b6bef9eddc9e7e0780ecda1488 to your computer and use it in GitHub Desktop.
Update Database every 3 Days..
<?php
$_updateday = 3;
$_endofdays = 31;
$_monthsend = 12;
$_days = date("d");
$_months = date("m");
$_nowday;
$_nowmonth;
$_moddays;
if($_days >= $_endofdays){
if($_months == $_monthsend){
$_moddays = "00";
$_nowmonth = 1;
}elseif($_months < $_monthsend){
$_moddays = $_endofdays;
$_nowmonth = $_months + 1;
}else{
$_moddays = $_endofdays;
$_nowmonth = $_months;
}
$_endofdays = $_moddays;
$_nowday = $_days - cal_days_in_month(CAL_GREGORIAN,date("m"),date("Y"));
$_nowday = $_nowday + $_updateday;//Add 3 more Days..
echo(date("Y-".($_nowmonth)."-".($_nowday))."\r\n");
}elseif($_days < $_endofdays){
$_endofdays = "00";
$_nowmonth = $_months;
$_nowday = $_days;
}
$_dateref = ((date("Y-m"))."-".($_endofdays));
$_refdate = date_create($_dateref);
$_date = date_create(date("Y-".($_nowmonth)."-".($_nowday)));
$_update = $_date -> diff($_refdate) -> format("%a");
$_mod = $_update % $_updateday;
switch($_mod){
case(0):
$_show_msg = "Fetch from Database..";
break;
case(1):
if($_update == 331){
//Normal Year (365) Days
$_show_msg = "Fetch from Database..";
}elseif($_update != 331){
$_show_msg = "Never Update..";
}
break;
case(2):
if($_update == 332){
//Leap Year (366) Days
$_show_msg = "Fetch from Database..";
}elseif($_update != 332){
$_show_msg = "Never Update..";
}
break;
default:
$_show_msg = "Never Update..";
break;
}
echo($_dateref."\r\n");
echo(($_date -> format("Y-m-d"))." : ".($_update)." : ".($_mod)." : ".($_show_msg)."\r\n");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment