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 21 2019, 07:12 PM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
I did a little research and found that date_format() is also a MySQL command (I've never needed it so I didn't know about it). Based on what I have read I see no reason why this line of code would not work:
CODE $q = "SELECT `file_no`, date_format(`sent_on`,'%d-%m-%Y'), FROM `filetrack` WHERE `sent_on` Between '$frmdate' and '$todate' order by `sent_on`"; Maybe because of the extra comma after date_format? And you didn't use the CAST() function. Like this: CODE $q = "SELECT `file_no`, DATE_FORMAT(`sent_on`,'%d-%m-%Y') FROM `filetrack` WHERE `sent_on` BETWEEN CAST('$frmdate' AS DATE) AND CAST('$todate' AS DATE) ORDER BY `sent_on`"; Remember, since you have to store the dates as 'YYYY-MM-DD' format make sure $frmdate and $todate are in the same format. Also it is a good idea to put all MySQL commands in upper case. |
Lo-Fi Version | Time is now: 28th April 2024 - 03:12 AM |