receive date from the datapicker as a Date

Asked

Viewed 165 times

1

I put in my site in Asp.net the datepicker of this website and I want to receive the value as Date instead of String , so that it does not give problems with the date type of other countries.

/* Brazilian initialisation for the jQuery UI date picker plugin. */
/* Written by Leonildo Costa Silva ([email protected]). */
( function( factory ) {
	if ( typeof define === "function" && define.amd ) {

		// AMD. Register as an anonymous module.
		define( [ "../widgets/datepicker" ], factory );
	} else {

		// Browser globals
		factory( jQuery.datepicker );
	}
}( function( datepicker ) {

datepicker.regional[ "pt-BR" ] = {
	closeText: "Fechar",
	prevText: "<Anterior",
	nextText: "Próximo>",
	currentText: "Hoje",
	monthNames: [ "Janeiro","Fevereiro","Março","Abril","Maio","Junho",
	"Julho","Agosto","Setembro","Outubro","Novembro","Dezembro" ],
	monthNamesShort: [ "Jan","Fev","Mar","Abr","Mai","Jun",
	"Jul","Ago","Set","Out","Nov","Dez" ],
	dayNames: [
		"Domingo",
		"Segunda-feira",
		"Terça-feira",
		"Quarta-feira",
		"Quinta-feira",
		"Sexta-feira",
		"Sábado"
	],
	dayNamesShort: [ "Dom","Seg","Ter","Qua","Qui","Sex","Sáb" ],
	dayNamesMin: [ "Dom","Seg","Ter","Qua","Qui","Sex","Sáb" ],
	weekHeader: "Sm",
	dateFormat: "dd/mm/yy",
	firstDay: 0,
	isRTL: false,
	showMonthAfterYear: false,
	yearSuffix: "" };
datepicker.setDefaults( datepicker.regional[ "pt-BR" ] );

return datepicker.regional[ "pt-BR" ];

} ) );

$(function() {  
  $("#datepicker").datepicker();
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.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>

<p>Date: <input type="text" id="datepicker"></p>

Someone can help me?

  • Your question is vague, what is the code ?

  • is on the site I left above, but follows here also "<script> $( Function() { $( "#datepicker" ).datepicker(); } ); </script> <p>Date: <input type="text" id="datepicker"></p>"

  • to receive the value of datepicker is that I do not know the code

  • I asked your question the example of the code is in English, and you wanted the date in Portuguese?

  • No. I want instead of receiving in string be in date so that regardless of where in the world the site runs there are no errors in the date format

  • Where are you running this... are you sending the value to where? That I don’t understand!

  • To store the date of birth in the database

  • if you have to put this code!

Show 4 more comments

1 answer

0

Good morning, below is a code that may be what you are looking for. The code besides showing the formatted date in the "datepicker" field in "Alternate" it shows without formatting, leaves original. link to documentation: https://jqueryui.com/datepicker/#alt-field Since Datepicker returns the date as a string you will have to convert the date in the backend, before sending it to the bank, using the Tryparse method.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Datepicker - Populate alternate field</title>
  <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>
  <script>
  $( function() {
    $( "#datepicker" ).datepicker({
      altField: "#alternate",
      altFormat: "DD, d MM, yy"
    });
  } );
  </script>
</head>
<body>
 
<p>Date: <input type="text" id="datepicker">&nbsp;<input type="text" id="alternate" size="30"></p>
 
 
</body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.