Home » Add ymd prototype method to Date object to format javascript dates as Y-m-d

Add ymd prototype method to Date object to format javascript dates as Y-m-d


If you’re like me and work with PHP and AJAX fairly often, then javascript date objects might be a bit cumbersome at times when it comes to formatting them in a Y-m-d format. Here’s a quick and handy prototype to take a javascript date object and format it as Y-m-d with a simple .ymd method.

Granted, for 90% of the things that I do with javascript Date objects I use momentjs, which is a gift from the gods when it comes to date manipulation. I highly recommend using momentjs if you’re doing anything like subtracting or adding increments of time to a Date object (similarly to how PHP’s date and strtotime functions make life easy with date manipulation).

If you have questions about using the above code, or even anything related to momentjs, feel free to post a comment 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *