The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Date format issue while fetching data
shankar from vizag
post 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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
CharlesEF
post 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>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
shankar from vizag   Date format issue while fetching data   May 14 2019, 09:33 AM
CharlesEF   Ok, I'm back. Yesterday was a long day, glad ...   May 14 2019, 11:10 AM
shankar from vizag   Ok, I'm back. Yesterday was a long day, glad...   May 15 2019, 08:11 PM
CharlesEF   The jQuery site provides a working example, found ...   May 16 2019, 12:32 AM
shankar from vizag   The jQuery site provides a working example, found...   May 17 2019, 09:28 AM
CharlesEF   Are you getting the date in the correct format? I...   May 17 2019, 09:49 AM
CharlesEF   Is your database column a DATE or DATETIME? If it...   May 17 2019, 12:00 PM
CharlesEF   Since I've not heard back from you I'm not...   May 18 2019, 01:09 PM
shankar from vizag   Since I've not heard back from you I'm no...   May 20 2019, 10:32 AM
CharlesEF   It seems MySQL supports ISO-8601 date/time values,...   May 20 2019, 11:26 AM
shankar from vizag   It seems MySQL supports ISO-8601 date/time values...   May 21 2019, 02:23 AM
shankar from vizag   It seems MySQL supports ISO-8601 date/time values...   May 21 2019, 09:43 AM
CharlesEF   Before I pick this code apart, please post the PHP...   May 21 2019, 10:26 AM
CharlesEF   I did a little research and found that date_format...   May 21 2019, 07:12 PM
shankar from vizag   I did a little research and found that date_forma...   May 22 2019, 09:10 AM
CharlesEF   Glad you got it working. Before I read about DATE...   May 22 2019, 02:41 PM
CharlesEF   FYI, as a test I put together a MySQL database tab...   May 22 2019, 06:44 PM


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th April 2024 - 09:10 AM