t4thilina
t4thilina

Reputation: 2197

Convert the date format 12/12/2013 into 2013-12-12

I'm using this Jquery plugin to get the date into a textbox. The default format given by this code is 12/12/2013. But I need to convert the format into 2013-12-12 since the database date figures I have already saved are in this format. So I need to compare 12/12/2013 with 2013-12-12. Since they are in different formats I can't compare them. So how can I convert the format 12/12/2013 into 2013-12-12.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
    $(function() {
      $( "#datepicker" ).datepicker();
    });
  </script>
</head>
<body>
  <p>Date: <input type="text" id="datepicker"></p>
</body>
</html>

Upvotes: 0

Views: 107

Answers (2)

Nouphal.M
Nouphal.M

Reputation: 6344

Try this :

$( "#datepicker" ).datepicker({
    dateFormat:'yy-mm-dd'   
});

You can find working demo here. For more info read this doc

Upvotes: 1

Krish R
Krish R

Reputation: 22721

You can try this,

 $( "#datepicker" ).datepicker( "option", "dateFormat", "yy-mm-dd" );

Ref: http://forum.jquery.com/topic/datepicker-change-date-format-from-mm-dd-yy-to-dd-mm-yy

Upvotes: 2

Related Questions