1

i'm passing start date as 7/02/2014 in dd/mm/yyyy format, to add one month extra for current passed date, first i need to convert the passed var item to Date format and then i can manipulate on it.

if i try to get date like this, var newDate = new Date(startDate.val()); then i will be getting new date as 7 july 2014, i.e format of date i'm getting in response is mm/dd/yyyy.

i need output of date() to be in dd/mm/yyyy format only. how to achieve this?

Is there any other function in jquery to do this?

dhana
  • 6,217
  • 4
  • 38
  • 61
Naruto
  • 9,284
  • 34
  • 114
  • 196

4 Answers4

3
var dateArr = '7/02/2014'.split('/');
var date = new Date();
date.setYear(dateArr[2]);
date.setMonth(dateArr[1] -1); //month starts from 0
date.setDate(dateArr[0]);
Vlad Nikitin
  • 1,901
  • 13
  • 16
3

Use jquery

var date = $.format.date(new Date(Date), 'dd/mm/yyyy'); 

https://github.com/phstc/jquery-dateFormat

Prashobh
  • 8,758
  • 14
  • 59
  • 90
0

Actually I recommend jQuery Datepicker. Because really simple and comprehensible.

You dont have any edits because datepicker default options show like this : dd/mm/yyyy

jQuery;

 $(function() {
   $( "#datepicker" ).datepicker();
 });

Html;

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

Check it : http://jqueryui.com/datepicker/

mehmetakifalp
  • 435
  • 5
  • 16
0

You can try this one

var newDate = new Date("2/7/2014");
var dateformat = newDate.getDate();
dateformat+="/";
dateformat+=newDate.getMonth()+1;
dateformat+="/";
dateformat+=newDate.getYear();
alert(dateformat);
THE ONLY ONE
  • 2,070
  • 1
  • 11
  • 6