Can you solve this problem? PHP 5.5 Date() problem

I can not find bug: // $_POST[‘…’] // coming from ajax POST request jquery

//$pickupDate = $_POST[‘pickupDate’]; // when this is uncommented I get correct date 04/11/2018 5:14 AM

//$pickupDate = date(“F j, Y, g:i a”, strtotime(“04/11/2018 5:14 AM”)); // when this uncommented I got: correct like April 11, 2018, 5:14 am

//$pickupDate = date(“F j, Y, g:i a”, strtotime($_POST[‘pickupDate’])); // but on this I get: January 1, 1970, 12:00 am

can you solve this problem?

www.PolisChrysochousTaxi.com I use Bootstrap picker as used here in home page

Works fine on ,y computer :slight_smile:

# TAXI Pickup time
# when this is uncommented I get correct date 04/11/2018 5:14 AM    
  echo '<br><br>',  
   $_POST['pickupDate'] = '04/11/2018 5:14 AM';
  $pickupDate = $_POST['pickupDate']; 

# when this uncommented I got: correct like April 11, 2018, 5:14 am
  # echo '<br><br>',  
  # $pickupDate = date("F j, Y, g:i a", strtotime("04/11/2018 5:14 AM")); 

# but on this I get: January 1, 1970, 12:00 am     
  echo '<br><br>',  
  $pickupDate = date("F j, Y, g:i a", strtotime($_POST['pickupDate'])); 
// TAXI Pickup time   

**Output:** ``` 04/11/2018 5:14 AM

April 11, 2018, 5:14 am

Try it as

$_POST['pickupDate'] = ' 04/11/2018 5:14 AM ';

or

$_POST['pickupDate'] = '4/11/2018 5:14 AM';

I tried all three and they all worked?

 echo '<dl>';  
    echo '<dt>';  
     echo $_POST['pickupDate'] = '04/11/2018 1:14 AM';
    echo '</dt><dd>',  
      $pickupDate = date("F j, Y, g:i a", strtotime($_POST['pickupDate'])); 

    echo '</dd><dt>';  
      echo $_POST['pickupDate'] = ' 04/11/2018 3:14 AM ';
    echo '</dt><dd>',  
    $pickupDate = date("F j, Y, g:i a", strtotime($_POST['pickupDate'])); 

    echo '</dd><dt>';  
      echo $_POST['pickupDate'] = '4/11/2018 5:14 AM';

  # but on this I get: January 1, 1970, 12:00 am     
    echo '</dt><dd>';  
    echo $pickupDate = date("F j, Y, g:i a", strtotime($_POST['pickupDate'])); 

  echo '</dd></dl>';

**Output:** ``` 04/11/2018 1:14 AM April 11, 2018, 1:14 am 04/11/2018 3:14 AM April 11, 2018, 3:14 am 4/11/2018 5:14 AM April 11, 2018, 5:14 am
1 Like

input in site date text box 04/09/2018 12:00 AM

// $pickupDate = $_POST['pickupDate'];
// $pickupDate = date("F j, Y, g:i a", strtotime($_POST['pickupDate']));

when have un-commented first line I get
04/09/2018 12:00 AM
in email got
but when active (un-commented) second line and commented first I get
January 1, 1970, 12:00 am

well ?

fixed was in JS

//characters we want to get rid off
var entityMap = {
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    '"': '&quot;',
    "'": '&#39;',
    "/": '&#x2F;'
  };

//remover caracteres de HTML y comillas
var escapeHTML = function (string) {
  return String(string).replace(/[&<>"'\/]/g, function (s) {
    return entityMap[s];
  });
}

		    pickupDate: escapeHTML($('#pickupDate').val()), // error 

		    pickupDate: $('#pickupDate').val(),  // fixed

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.