Announcement

Collapse
No announcement yet.

macro sc_date_dif with todays date

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    Validate the date given against today's date how? What is it you want to know about the date given?

    Comment


    • #3
      Hello,

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

      Regards
      Erwin

      Comment


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

        Code:
        $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.";
        }

        Comment


        • #5
          This works, thank you!

          Comment

          Working...
          X