Date format issue while fetching data |
Date format issue while fetching data |
shankar from vizag |
May 14 2019, 09:33 AM
Post
#1
|
Advanced Member Group: Members Posts: 202 Joined: 18-June 13 Member No.: 19,316 |
Greetings
In my php page, I have used JQuery datepicker and it is working fine when the function as follows: <script> $("#myDatepicker").datepicker({dateFormat: 'yy-mm-dd'}); </script> But, I need the format as dd-mm-yy. When I tried to change the format as below, <script> $("#myDatepicker").datepicker({dateFormat: 'dd-mm-yy'}); </script> the date is saving in table as 0000-00-00. Kindly help me out to overcome this issue. regards |
CharlesEF |
May 20 2019, 11:26 AM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
It seems MySQL supports ISO-8601 date/time values, and no others. This means you will have to convert your date to 'YYYY-MM-DD' format in order to store it in the database. When you pull the date out of the database you need to convert it back to 'DD-MM-YYYY' format. MySQL is converting your dates to '0000-00-00'.
|
shankar from vizag |
May 21 2019, 09:43 AM
Post
#3
|
Advanced Member Group: Members Posts: 202 Joined: 18-June 13 Member No.: 19,316 |
It seems MySQL supports ISO-8601 date/time values, and no others. This means you will have to convert your date to 'YYYY-MM-DD' format in order to store it in the database. When you pull the date out of the database you need to convert it back to 'DD-MM-YYYY' format. MySQL is converting your dates to '0000-00-00'. Charless ji I tried the following code instead of inserting the dd-mm-yyyy to fetch from the database table to php with mysql query, but failed <?php $link = mysqli_connect("localhost","root",""); mysqli_select_db($link,"fts"); if(isset($_POST['search'])){ $frmdate=$_POST['frmdate']; $todate=$_POST['todate']; $q = "SELECT `file_no`, date_format(`sent_on`,'%d-%m-%Y'), FROM `filetrack` WHERE `sent_on` Between '$frmdate' and '$todate' order by `sent_on`"; $query = mysqli_query($link,$q); while($res=mysqli_fetch_array($query)){ ?> <tr> <td><?php echo $res['file_no'];?></td> <td><?php echo $res['sent_on'];?></td> <?php } ?> |
Lo-Fi Version | Time is now: 28th April 2024 - 09:11 AM |