-1

I have used a datepicker in my <input> tag, and when I select a date (like 2013-12-27), then I wanted the selected date to be displayed as December 27, 2013 in my script.

<input type="text" id="datepicker" name="date" required="true"/>    

How can we achieve this?

Rahul Desai
  • 15,242
  • 19
  • 83
  • 138
Sapthagiri
  • 111
  • 5

3 Answers3

1

Try this

var date = $('#datepicker').datepicker({ dateFormat: 'MM d, yy' }).val();
norbdum
  • 2,361
  • 4
  • 19
  • 23
0

You need to specify the date format explicitly in jQuery.

Try this:

$( "#datepicker" ).datepicker({ dateFormat: 'MM dd, yy' });

Working Demo

Rahul Desai
  • 15,242
  • 19
  • 83
  • 138
0

You can refer following answer for custom date function library.

Calculating Date in JavaScript

I have copied the below answer from above link

Please find attached link for Date Library to get the custom calculation date and time functions.

To use it client side, download index.js and assertHelper.js and include that in your HTML.

<script src="assertHelper.js"></script>
<script type="text/javascript" src="index.js"></script>
$( document ).ready(function() {
    DateLibrary.getDayOfWeek(new Date("2015-06-15"),{operationType:"Day_of_Week"}); // Output : Monday
}

You can use different functions as given in examples to get custom dates.

To get First Day of quarter From Given Date

DateLibrary.getRelativeDate(new Date("2015-06-15"),
    {operationType:"First_Date",granularityType:"Quarters"}) // Output : Wed Apr 01 2015 00:00:00

If first day of week is Sunday, what date will be on Wednesday, if given date is 15th June 2015

DateLibrary.getRelativeDate(iDate,
    {operationType: "Date_of_Weekday_in_Week",
        startDayOfWeek:"Sunday",returnDayOfWeek:"Wednesday"}) // Output : Wed Jun 17 2015 00:00:00

If first day of week is Friday, what date will be on Tuesday of 3rd Week of 2nd month of 3rd quarter of year containing 15th June 2015 as one of the date.

DateLibrary.getRelativeDate(new Date("2015-06-15"),
    {operationType: "Date_of_Weekday_in_Year_for_Given_Quarter_and_Month_and_Week",
        startDayOfWeek:"Friday",returnDayOfWeek:"Tuesday", QuarterOfYear:3, MonthOfQuarter:2, WeekOfMonth:3}) // Output : 18th Aug 2015

If first day of week is Tuesday, what week number in year will be follow in 15th June 2015 as one of the date.

 DateLibrary.getWeekNumber(new Date("2015-06-15"),
    {operationType:"Week_of_Year",
        startDayOfWeek:"Tuesday"}) // Output : 24

There are Date Difference functions also available

 DateLibrary.getDateDifference(new Date("2016-04-01"),new Date("2016-04-16"),
    {granularityType: "days"}) //output 15

Function for Convert number to Timestr

DateLibrary.getNumberToTimeStr("345", {delimiter: ":"}) //output 00:03:45

It also supports Julian date conversion

 DateLibrary.julianToDate("102536") //output Fri Jun 20 2003 00:00:00
Community
  • 1
  • 1
Vikash Rajpurohit
  • 1,525
  • 2
  • 13
  • 13