Friday, October 26, 2007

Month last day salary - PHP Script

Month last day salary if not Sat, Sun if yes than salary on Friday
<?php
ini_set("display_error","1");
error_reporting(E_ALL);

$mysqli = new mysqli('localhost','root','','test');

if($mysqli->connect_errno){
echo "error".$mysqli->connect_error;
}
$start = $month = strtotime('2017-12-01');
$end = strtotime('2018-12-01');
while($month <= $end)
{
     echo $day = date("D", strtotime(date('Y-m-t', $month)));
echo $date = date('Y-m-t', $month);
if($day == 'Sun'){
$date = date('Y-m-d', strtotime('-2 day', strtotime($date)));
}

if($day == 'Sat'){
$date = date('Y-m-d', strtotime('-1 day', strtotime($date)));
}

echo "<br>Salary Date For Employee is ". $date."<br>";
    $month = strtotime("+1 month", $month);

$sql = "INSERT INTO  `test`.`employee` (`id` ,`name` ,`salary` ,`salarydate`) VALUES (NULL ,  'amit',  '1000',  '$date')";
//$res = $mysqli->query($sql);

}
?>