RPB
RPB

Reputation: 16320

How to get current date using jquery?

I am using a calender plug-in and I want to populate the current date into a text field. How can I do this using jquery?

Upvotes: 6

Views: 44104

Answers (2)

Naveed
Naveed

Reputation: 42093

You can get current date in JavaScript:

var now = new Date();

If you are using jQuery DatePicker you can apply it on any textfield like this:

$('input.youTextFieldClass').datepicker({ dateFormat: 'mm/dd/yy', 
                                     changeMonth: true,
                                     changeYear: true,
                                     yearRange: '-70:+10',
                                     constrainInput: false,
                                     duration: '',
                                     gotoCurrent: true});

If you want to set current date in textfields as page load:

$("input.youTextFieldClass").datepicker('setDate', new Date());

Upvotes: 12

Arun P Johny
Arun P Johny

Reputation: 388316

You can find the sample here.

<input type="text" id="datepicker">
$( "#datepicker" ).datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date());

Upvotes: 2

Related Questions