Check validation if date is < 3 months
You are putting your date into an array and then comparing it to a timestamp. Why are you doing that?
Assuming $current_employee->emp_dtentry
is a Unix timestamp:
if ($current_employee->emp_dtentry < strtotime('+3 months')) {
If it is not a Unix timestamp and is a valid date format you can do:
if (strtotime($current_employee->emp_dtentry) < strtotime('+3 months')) {
If it is not a valid date format you would need to use DateTime::createFromFormat()
to parse the date and then do your comparison. That is easier to do with DateTime objects throughout.
// see manual format options$empdtEntry = DateTime::createFromFormat('<format goes here>', ($current_employee->emp_dtentry); $current_employee->emp_dtentry);$threeMonthsFromNow = new DateTime(+3 months);if ($empdtEntry < $threeMonthsFromNow ) {
As you are redirecting, your echo won't work. Either flash your javascript or use javascript there to redirect too.
Using flash:
$dateEntry = $current_employee->emp_dtentry; if ($dateEntry < strtotime('+3 months')) { $this->session->set_flashdata("javascript", "<script>alert('you don't have the right to access this menu')</script>"); redirect('new_leave'); }
Then within the new_leave
view check it if exists and echo it:
if($this->session->flashdata('javascript')){ echo $this->session->flashdata('javascript');}
Or using javascript do it as below:
$dateEntry = $current_employee->emp_dtentry; if ($dateEntry < strtotime('+3 months')) { echo "<script>alert('you don't have the right to access this menu'); window.location.href='new_leave';</script>"; }