How make validation of Date with datetime work with jquery(date picker) for php?

By JOnatha Flint

Script(jquery) use to make input[date] accessible to multiple browser(datepicker)

      if (! { //if browser doesn't support input type="date", initialize date picker widget:
    // If not native HTML5 support, fallback to jQuery datePicker <script src="js/realtime_validityScript.js">
            // Consistent format with the HTML5 picker
                **dateFormat: 'dd-mm-yy',**
                maxDate: 0
            // Localization

PHP code for validating date format by user in case jquery is disabled (not working) – also not sure how to use DateTime::getLastErrors()

// specify your date's original format, in this example d/m/Y (e.g. 25/07/2014)
 **$format = "d-m-Y";**
 $date = DateTime::createFromFormat($format, $_POST['DateField']);
 $date_errors = DateTime::getLastErrors();
  if(? $date_errors[also dunno what to put here?] ) {
   // createFromFormat returns false if the format is invalid;
   echo 'Your date format is incorrect';
 } else {
   //change it to any format you want with format() (e.g. 2013-08-31)

Original PHP code for getting my date: (my db access currently this format “Y-m-d”)

if (empty($_POST["DateField"]) ) {
   $errors['DateField'] = "Age is required";
} else {
    $date = date("Y-m-d", strtotime( $_POST['DateField']));

Thanks you for your support…still new to PHP would really help if someone could expl to me what wrong and what the correct code

Source: Stack Overflow


Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273