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 18 2019, 01:09 PM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Since I've not heard back from you I'm not exactly sure what you need help with. Here is a working example. Remember, 'dd-mm-yy' is not well supported in Javascript but PHP seems to support it better. But, I would not count on it.
CODE <?php if(isset($_POST["submitit"])) { date_default_timezone_set("America/Chicago"); $date = new DateTime($_POST["datepicker"]); echo($date->format("Y-m-d")); } ?> <!doctype html> <html lang="en"> <head> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <link rel="stylesheet" href="/resources/demos/style.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <form action="<?php echo($_SERVER["PHP_SELF"]); ?>" method="post" accept-charset="UTF-8"> <p> <label for="datepicker">Enter Date:</label><br> <input type="text" id="datepicker" name="datepicker"> </p> <p> <input type="submit" id="submitit" name="submitit" value="Submit"> </p> </form> <script> window.onload = function() { $("#datepicker").datepicker({ dateFormat: "dd-mm-yy" }); } </script> </body> </html> |
Lo-Fi Version | Time is now: 26th April 2024 - 02:15 PM |