You can create one with:-
Date.prototype.addDays = function(days) { var date = new Date(this.valueOf()); date.setDate(date.getDate() + days); return date; } var date = new Date(); console.log(date.addDays(5));
This takes care of automatically incrementing the month if necessary. For example:
8/31 + 1 day will become 9/1.
The problem with using setDate
directly is that it’s a mutator and that sort of thing is best avoided. ECMA saw fit to treat Date
as a mutable class rather than an immutable structure.
Related Posts:
- Add days to JavaScript Date
- Compare two dates with JavaScript
- Getting current date and time in JavaScript
- Validate date in dd/mm/yyyy format using JQuery Validate
- Convert normal date to unix timestamp
- Check time difference in Javascript
- How to convert date to timestamp?
- How to format a JavaScript date
- How to format a JavaScript date
- How do I get the current date in JavaScript?
- Get String in YYYYMMDD format from JS date object?
- Compare dates with javascript
- Parsing a string to a date in JavaScript
- Current time formatting with Javascript
- Format JavaScript date as yyyy-mm-dd
- Moment js date time comparison
- How to validate date with format “mm/dd/yyyy” in JavaScript?
- How do I get the current time only in JavaScript
- How do I get the day of week given a date?
- Convert UTC date time to local date time
- How to subtract date/time in JavaScript?
- Shortest way to print current year in a website
- How to calculate date difference in JavaScript?
- How to change date format in JavaScript
- Convert a Unix timestamp to time in JavaScript
- How to subtract days from a plain Date?
- How to add 30 minutes to a JavaScript Date object?
- How to sort an object array by date property?
- How do you convert a JavaScript date to UTC?
- Convert UTC Epoch to local date
- How to format a UTC date as a `YYYY-MM-DD hh:mm:ss` string using NodeJS?
- Moment Js UTC to Local Time
- What’s a Good Javascript Time Picker?
- Get hours difference between two dates in Moment Js
- Javascript: getFullyear() is not a function
- How can I submit a form using JavaScript?
- How to do a redirect to another route with react-router?
- Jest spy on functionality
- Use a JSON array with objects with javascript
- Toggle show/hide on click with jQuery
- JavaScript string newline character?
- How to create a GUID / UUID
- How does “/\s/g” replace spaces with other characters?
- What is the correct way to check for string equality in JavaScript?
- JavaScript TypeError: Cannot read property ‘style’ of null
- How to obtain username from Promise
? - How do you check if a variable is an array in JavaScript?
- How to compare arrays in JavaScript?
- Rock, Paper, Scissors in JavaScript
- Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browser
- window.variableName
- What does ${} (dollar sign and curly braces) mean in a string in Javascript?
- How to implement authenticated routes in React Router 4?
- How to create a JQuery Clock / Timer
- Play an audio file using jQuery when a button is clicked
- How can I get the last character in a string?
- getBoundingClientRect is not a function
- Can a for loop increment/decrement by more than one?
- Example JavaScript code to parse CSV data
- addEventListener not working in javascript
- How to access the request body when POSTing using Node.js and Express?
- How do I check whether a checkbox is checked in jQuery?
- Reload an iframe with jQuery
- JavaScript pattern for multiple constructors
- How to manage a redirect request after a jQuery Ajax call
- ZIP Code (US Postal Code) validation
- Is there a standard function to check for null, undefined, or blank variables in JavaScript?
- How to force JavaScript to deep copy a string?
- How to go to a URL using jQuery?
- Uncaught ReferenceError: ga is not defined
- Getting or changing CSS class property with Javascript using DOM style
- How to close a window using jQuery
- Convert UTC date time to local date time
- WP Rest API – How to get featured image
- How to only enqueue block javascript on the frontend when its needed [duplicate]
- Eliminate render blocking javascript
- is_front_page() not working
- The value of attribute [ data-type ] must be in double quotes – custom html widget error
- Add tinymce dynamically via Javascript
- Make TinyMCE checkbox that returns a value instead of true/false
- TypeError: window.tinyMCE.execInstanceCommand is not a function
- Adding JavaScript to a WordPress website
- wp-env mysqlcheck error:1130
- event/callback on block update?
- How to disable inline css styles generated by Gutenberg editor?
- Multiple Conditional Controllers
- Adding javascript trigger to user role selection on the user-edit page
- Vue and wordpress.Bad Request ajax request
- How to add if lt IE9 conditional scripts to functions.php
- How to include a JSON file on my page?
- How to add “on change” to a text input in contact form7?
- Update media library attachments
- JavaScript Libraries in WordPress
- How to use WP switchEditors.switchto(this) JS function in your own script?
- Landing function through URL
- Escaping quotes while enqueuing scripts
- Combining results from WP-API using AngularJS
- Anyway to disable the auto excerpt creation?
- How do I cycle a JS function in WordPress? [closed]
- Why is this script not working?