0
var today = new Date();
var tomorrow = today;
tomorrow.setDate(tomorrow.getDate() +1);

function formatDateToString(date) { 
  var dd = (date.getDate() < 10 ? '0' : '') 
      + date.getDate(); 

  return dd;
}

how can I store and use the return value in a variable?

2
  • 1
    Yes it is ... future is "05", and today is the 4th ... have you even run your code as posted to test? Perhaps the real code is different to what you've posted ... Note .. changing the date of tomorrow will change today and vice-versa as they are the same object Commented Aug 4, 2020 at 9:30
  • you can easily do var ddResult = formatDateToString(); the return value dd will now be in ddResult. Commented Aug 4, 2020 at 14:41

1 Answer 1

1

Since the function is returning a value you can assign the returned value to the variable like this:

var returned = formatDateToString(date);
Sign up to request clarification or add additional context in comments.

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.