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,487
  • 4
  • 40
  • 63
Naruto
  • 9,476
  • 37
  • 118
  • 201

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,929
  • 15
  • 17
3

Use jquery

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

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

Prashobh
  • 9,216
  • 15
  • 61
  • 91
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
  • 445
  • 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,110
  • 1
  • 12
  • 6