0

javascript code is

 var lastday = new Date(curr.setDate(curr.getDate() - curr.getDay() + 5));

I am getting output

Fri Oct 25 2013 17:15:12 GMT+0530 (India Standard Time)

The output is correct but i want output something like

25/10/2013

How can i get this?

Thanks

2

2 Answers 2

3

You'll need to format the date object using the API:

var str = lastday.getDate() + "/" + (lastday.getMonth() + 1) + "/" + lastday.getFullYear();
Sign up to request clarification or add additional context in comments.

2 Comments

@Qantas94Heavy Yeah. Fixed.
@Qantas94Heavy Haha, yeah, you got me! I was correct the first time ^^
0

Yes, you can do it like:

var lastday = new Date(curr.setDate(curr.getDate() - curr.getDay() + 5));

var date = lastday.getDate();

// 1 is added since it's zero-based value 
// (where zero indicates the first month of the year).
var month = lastday.getMonth() + 1;      
var year = lastday.getFullYear();

// You can change the format to like 'dd/mm/yyyy' or 'mm/dd/yyyy'
// based on your requirements below
var newDate = date + '/' + month + '/' + year;


console.log(newDate); // 25/10/2013

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.