Rithu
Rithu

Reputation: 1289

PHP validation in comparison of start and end date

The below coding shows the comparison of start and end date and shows error if end date is greater than start date

But what I want to do is how to write the same functionality in full PHP code I don't know. Could anybody help to write the below functionality in PHP coding

HTML

<input type="text" id="starddate" />
<input type="text" id="enddate" />
<div id="msg"></div>
<input type="submit" id="submit" />

JQuery

jQuery.validator.addMethod("greaterThan", 
function(value, element, params) {

    if (!/Invalid|NaN/.test(new Date(value))) {
        return new Date(value) > new Date($(params).val());
    }

    return isNaN(value) && isNaN($(params).val()) 
        || (parseFloat(value) > parseFloat($(params).val())); 
},'Must be greater than {0}.');

$("#enddate").rules('add', { greaterThan: "#startdate" });

Upvotes: 0

Views: 7866

Answers (1)

Laurence
Laurence

Reputation: 60048

if ((strtotime($_POST['startdate'])) > (strtotime($_POST['enddate'])))
{
    // Start date is in front of end date!
}
else
{
    // Ok
}

Upvotes: 4

Related Questions