2

I am doing a project in ASP.NET , c#.

I have .aspx view in which i took a datpicker for approval Date.

I am fetching value of datepicker on OnChange event.

My datepicker in .aspx view look like:

 <%: Html.Telerik().DatePickerFor(model => model.ApprovalDate).ClientEvents(events => events.OnChange("OnChangeDatePicker"))%>

I have a javascript function which am calling on OnChange event of datepicker.

function OnChangeDatePicker(e) {
   ApprovalDate = e.date;
}

In ApprovalDate am getting value of datepicker as :Wed Aug 2 00:00:00 UTC+0530 2013

But i want the date in mm/dd/yyyy format.

Any suggestions would be appreciated...

Ishank
  • 2,860
  • 32
  • 43
Keren Caelen
  • 1,466
  • 3
  • 17
  • 38
  • http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript refer this – Anuj Jun 07 '13 at 10:10

2 Answers2

5

One way is -

var d = new Date('Wed Aug 2 00:00:00 UTC+0530 2013');
var newDate = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear();

EDIT, just found this works too:

var newDate =d.toLocaleDateString();
Ishank
  • 2,860
  • 32
  • 43
0

getDate(): Returns the date,getMonth(): Returns the month,getFullYear(): Returns the year

you can achieve your requirement by retrieving date month and year seperatly and then concating the three parts to get your format.

 <script type="text/javascript">

        var date = ApprovalDate.getDate();
        var month = ApprovalDate .getMonth() + 1; //Months are zero based
        var year = ApprovalDate .getFullYear();
      var formattedDate=month+ "/" + date  + "/" + year;
    </script>
Ishank
  • 2,860
  • 32
  • 43
Anuj
  • 1,496
  • 1
  • 18
  • 28
  • you are welcome,there are several methods you can use http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript – Anuj Jun 07 '13 at 10:21