0

I want to change date format sequence from yy-mm-dd to dd-mm-yy

How can I do it in Javascript ?

I have tried

var now = new Date();

now.format("mm-dd-yy");

But its not working for me

6
  • 1
    if you want dd-mm-yy, then why does your code say mm-dd-yy? Commented Dec 19, 2013 at 13:47
  • Do you already have a date in yy-mm-dd format or are you trying to do it for now? Commented Dec 19, 2013 at 13:48
  • Not so hard to check on internet... webdevelopersnotes.com/tips/html/… Commented Dec 19, 2013 at 13:49
  • Out of curiosity, what let you to think that Date objects had a format function? You can easily look up a list of functions that are available to the object... w3schools.com/jsref/jsref_obj_date.asp Commented Dec 19, 2013 at 13:51
  • @Tim Just imagine I have used a date with format mm-dd-yy in 100 places, but it want same date in dd-mm-yy format in one place. Thats why Commented Dec 20, 2013 at 7:31

4 Answers 4

1

Here is a clear and simple approach

var now = new Date();     
var dd = now.getDate();    //returns date
var mm = now.getMonth()+ 1; //returns month and you need to add1 because it is array
var yy = now.getFullYear(); //returns full year 
var st = dd + '-' + mm  + "-" + yy;  //format as string
Sign up to request clarification or add additional context in comments.

Comments

0
var dateFormatted = (now.getMonth()+1)+"-"+now.getDate()+"-"+now.getFullYear();

Comments

0

You can use the below mentioned function to format Date

utilities.FormatDate(new Date(),"GMT", "dd/MM/yyyy")

1 Comment

...if you use Google Apps, that is.
0
function dateformat(date)
{
  var yourdate = new Date(date);
 yourdate = yourdate.getDate() + '-' + yourdate.getMonth() +1 + "-"  +yourdate.getFullYear();
}

use - or / as you like

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.