0

I am trying to get the script to display yesterdays date in "m/d/yy" format. When I use this code:

<p>
    Here is the report for 
    <script>
        var yesterday = new Date();
        yesterday.setDate(yesterday.getDate() - 1);
        document.write(yesterday.format("m/d/yy"));
    </script>
    .
</p>

this is returned:

Here is the comparison report for .

if I put it in without the .format("m/d/yy"), I get this:

Here is the comparison report for Thu Mar 27 2014 15:42:31 GMT-0700 (Pacific Daylight Time) .

What am I doing wrong?

Makai
  • 567
  • 3
  • 9
  • 18
  • 10 ways to format time and date in JS: http://www.webdevelopersnotes.com/tips/html/10_ways_to_format_time_and_date_using_javascript.php3 and also this existing SO question has information: http://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript – Goose Mar 28 '14 at 22:50

1 Answers1

0
document.write(yesterday.getMonth() + "/" + yesterday.getDay() + "/" +  yesterday.getFullYear())

The date object has many methods for displaying various parts of it. See here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Jabbath
  • 334
  • 1
  • 3
  • 11