macro sc_date_dif with todays date

Hi,

i want to validate a given date against the date of today, how is this done?

Regards

Erwin

Validate the date given against today’s date how? What is it you want to know about the date given?

Hello,

i want to know if thegiven date is not before today!

Regards
Erwin

You need to make sure both dates to be compared are Datetime format - so if they are strings, convert them first.

$date_given = date('Y-m-d', strtotime({date_given}));     // Assumes the date given is in field {date_given} - convert to datetime with format of yyyy-mm-dd

$diff = sc_date_dif($date_given, "yyyy-mm-dd", date('Y-m-d'), "yyyy-mm-dd");    // calculates days difference between 2 dates - today's date is the "date('Y-m-d')"

if ($diff < 0) {
    echo $date_given . " is " . $diff . " days older than today.";
} else if ($diff = 0) {
    echo $date_given . " equals today.";
} else {    // i.e. $diff > 0
    echo $date_given . " is " . $diff . " days newer than today.";
}

This works, thank you!