Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery date picker get date string in dd/mm/yy

I have the string

'Thu Oct 20 2011 00:00:00 GMT-0400 (Eastern Daylight Time)'

and would like to get date in format dd/mm/yyyy out of this. How can I do this using jquery date picker library?

like image 477
kk1957 Avatar asked Oct 21 '11 03:10

kk1957


People also ask

How to change date format in datepicker jQuery?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How to set date format dd mm yyyy in jQuery?

Re: convert Date from YYYY-MM-DD to MM/DD/YYYY in jQuery/JavaScript. var tempDate = new Date("2021-09-21"); var formattedDate = [tempDate. getMonth() + 1, tempDate. getDate(), tempDate.

How do I insert date format in date picker?

The solution is to use the date picker dateFormat option. ..and use the following code to change the format with the dateFormat option. We have set it to 'dd-mm-yy'. View the file in a browser and select a date.

How to set default date format in jQuery datepicker?

Then call datepicker on elements with that class with your default configuration: $('. my-datepicker'). datepicker({ dateFormat: 'yy-mm-dd' });

How to set DD/MM/YYYY date format in jQuery datepicker?

The jQuery DatePicker plugin supports multiple Date formats and in order to set the dd/MM/yyyy Date format, the dateFormat property needs to be set. The following HTML Markup consists of a TextBox which has been made Read Only.

What is DD-MM-YYYY jQuery plugin?

Yet another jQuery datepicker plugin that pick date with dd-mm-yyyy format. The plugin attaches a popup calendar to given input field or shows an inline calendar for selecting individual dates or date ranges. How to start using jQuery?

How to get date from date picker to display image?

The code is supposed to take the date from date picker, combine it in a string which is to have the necessary code to display tag, images are located in /image and in the format aYY-MM-DD.png, new to this date picker and can't quite get it down yet.

How can I use DD/MM/YYYY as a date validator?

You already have the dateITA validator, which uses dd/mm/yyyy format as you need. Just like the date validator, your code for dateGreaterThan and dateLessThan calls new Date for input string and has the same issue parsing dates. You can use a function like this to parse the date: Show activity on this post. Show activity on this post.


5 Answers

This is a dupe question asked here before: jQuery UI DatePicker - Change Date Format

You can do this:

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

Just to note though, the JqueryUIDatePicker has a formatdate and parseDate function too.

like image 144
gideon Avatar answered Oct 01 '22 21:10

gideon


You can use the javascript Date() method

var dateTime = new Date($("#yourSelector").datepicker("getDate"));

var strDateTime =  dateTime.getDate() + "/" + (dateTime.getMonth()+1) + "/" + dateTime.getFullYear();

console.log(strDateTime);
like image 39
dCrystal Avatar answered Oct 01 '22 22:10

dCrystal


If you already set dateFormat parameter in datepicker initiation, you may use only

    $( ".selector" ).val();

Because, else, using :

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

is causing datepicker's onSelect event not to be triggered (don't know why, just observed).

like image 34
guylabbe.ca Avatar answered Oct 01 '22 22:10

guylabbe.ca


try having a look at http://docs.jquery.com/UI/Datepicker/formatDate

like image 43
Keith Nicholas Avatar answered Oct 01 '22 20:10

Keith Nicholas


Initialize a datepicker with the dateFormat option specified.

$( ".selector" ).datepicker({ dateFormat: 'dd/mm/yyyy' });

Get or set the dateFormat option, after init.

//getter
var dateFormat = $( ".selector" ).datepicker( "option", "dateFormat" );
//setter
$( ".selector" ).datepicker( "option", "dateFormat", 'dd/mm/yyyy' );
like image 36
xdazz Avatar answered Oct 01 '22 21:10

xdazz