Convert string to datetime from jQueryUI datepicker using strtotime

I am using jQueryUI datepicker and here is the code.

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css"> <script> $(function() { $( "#from" ).datepicker({ defaultDate: "+1w", changeMonth: true, numberOfMonths: 3, onClose: function( selectedDate ) { $( "#to" ).datepicker( "option", "minDate", selectedDate ); } }); $( "#to" ).datepicker({ defaultDate: "+1w", changeMonth: true, numberOfMonths: 3, onClose: function( selectedDate ) { $( "#from" ).datepicker( "option", "maxDate", selectedDate ); } }); }); </script> <form action="{LINKTO_EXPORT}" method="post"> <h1>{EXPORT_CSV}</h1> <label for="from">from</label> <input type="text" id="from" name="from"> <label for="to">to</label> <input type="text" id="to" name="to"> <input type="submit" value="{EXPORT_TEXT}"> </form> 

When I send from and to,

 $fromstr = $_POST["from"]; $tostr = $_POST["to"]; $from = date('Ymd H:i:s',strtotime($fromstr." 02:00:00")); $to = date('Ymd H:i:s',strtotime($tostr." 02:00:00")); 

to was converted correctly, i.e. 2015-06-13 02:00:00 , but from does not have. Instead, he returned on 6/1/2015 2:00 . To make sure that I get the correct values, I repeated the $fromstr and $tostr .

$fromstr returned 6/1/2015 $tostr returned 06/13/2015

Why did m / d / yyyy return from , and to do mm / dd / yyyy? How to convert m / d / yyyy string to timestamp? Please help, thanks!

+6
source share
1 answer

Try it.

Download next js

 <link rel="stylesheet" type="text/css" href="http://xdsoft.net/scripts/jquery.datetimepicker.css"/> <script src="http://xdsoft.net/scripts/jquery.datetimepicker.js"></script> 

You cannot use directly, so download js and css.

  <script> $(function() { $('#datetimepicker8').datetimepicker({ onGenerate:function( ct ){ $(this).find('.xdsoft_date') .toggleClass('xdsoft_disabled'); }, minDate:'-1970/01/2', maxDate:'+1970/01/2', timepicker:false }); $('#datetimepicker9').datetimepicker({ onGenerate:function( ct ){ $(this).find('.xdsoft_date') .toggleClass('xdsoft_disabled'); }, minDate:'-1970/01/2', maxDate:'+1970/01/2', timepicker:false }); }); </script> <input type="text" id="datetimepicker8"/> <input type="text" id="datetimepicker9"/> 
+1
source

Source: https://habr.com/ru/post/987972/


All Articles