How to make From date later than To date

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
vintoICT
User
Posts: 435

How to make From date later than To date

Post by vintoICT »

I have 2 date fields for when a candidate got a degree . One is DATE FROM AND THE OTHER IS DATE T0
I want a warning or pop if to date is later than from date. eg if FROM date is 12/2/1990 to date can not be 10/1/1989 .


mobhar
User
Posts: 11905

Post by mobhar »

You may simply use Row_Inserting and/or Row_Updating server event, for example:

if (strtotime($rsnew["DateFrom"]) > strtotime($rsnew["DateTo"])) {
    $this->setFailureMessage("<strong>Date From</strong> cannot be greater than <strong>Date To</strong>.");
    return false;
}

vintoICT
User
Posts: 435

Post by vintoICT »

got this error in php 8.2
PHP Deprecated: strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated


mobhar
User
Posts: 11905

Post by mobhar »

You may improve the code by checking whether the value is empty (null) or not:

if (!empty($rsnew["DateFrom"]) && !empty($rsnew["DateTo"])) {
  if (strtotime($rsnew["DateFrom"]) > strtotime($rsnew["DateTo"])) {
    $this->setFailureMessage("<strong>Date From</strong> cannot be greater than <strong>Date To</strong>.");
    return false;
  }
}

Post Reply