UPDATED: January 19, 2016
As of moment 2.8.4 – use .add(5, 'd')
(or .add(5, 'days')
) instead of .add('d', 5)
var new_date = moment(startdate, "DD-MM-YYYY").add(5, 'days');
Thanks @Bala for the information.
UPDATED: March 21, 2014
This is what you’d have to do to get that format.
startdate = "20.03.2014"; var new_date = moment(startdate, "DD-MM-YYYY").add('days', 5); var day = new_date.format('DD'); var month = new_date.format('MM'); var year = new_date.format('YYYY'); alert(day + '.' + month + '.' + year);
ORIGINAL: March 20, 2014
You’re not telling it how/what unit to add. Use –
var new_date = moment(startdate, "DD-MM-YYYY").add('days', 5);
Related Posts:
- Moment js date time comparison
- Moment.js transform to date object
- Moment Js UTC to Local Time
- Get hours difference between two dates in Moment Js
- Add JavaScript object to JavaScript object
- What is console.log?
- Can I use complex HTML with Twitter Bootstrap’s Tooltip?
- How do I redirect to another webpage?
- Invariant Violation: Objects are not valid as a React child
- How can I merge properties of two JavaScript objects dynamically?
- In reactJS, how to copy text to clipboard?
- SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag
- Uncaught SyntaxError: Invalid or unexpected token
- JavaScript TypeError: Cannot read property ‘style’ of null
- Invalid shorthand property initializer
- nodejs – error self signed certificate in certificate chain
- How do I loop through or enumerate a JavaScript object?
- Getting Unexpected Token Export
- Uncaught TypeError: Cannot read property ‘props’ of null
- How to use iMonkey in an iOS app
- What’s the difference between “Array()” and “[]” while declaring a JavaScript array?
- Mouseover & Mouseout w/ Javascript
- Format JavaScript date as yyyy-mm-dd
- Programmatically change the src of an img tag
- Unable to preventDefault inside passive event listener
- Angular JS Uncaught Error: [$injector:modulerr]
- Nested objects in javascript, best practices
- Scroll Automatically to the Bottom of the Page
- npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself
- How do I check if string contains substring?
- How to change date format in JavaScript
- OnChange event handler for radio button (INPUT type=”radio”) doesn’t work as one value
- InvalidValueError: not an instance of HTMLInputElement
- How to clear react-native cache?
- Execute PHP function with onclick
- blocked a frame of origin “null” from accessing a cross-origin frame – chrome
- How can I resolve the error “URL scheme must be “http” or “https” for CORS request.” for this code [duplicate]
- Initializing an Array with a Single Value
- Is it possible to stop JavaScript execution?
- Remove commas from the string using JavaScript
- How can you remove all documents from a collection with Mongoose?
- TypeError: ‘undefined’ is not an object
- How to set Angular 4 background image?
- React-Router : What is the purpose of IndexRoute?
- SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- Add new attribute (element) to JSON object using JavaScript
- D3 Appending Text to a SVG Rectangle
- Retrieve the position (X,Y) of an HTML element
- JQuery get the title of a button
- How to open a URL using PHP?
- Trying to load jquery into tampermonkey script
- Atom JavaScript Autocomplete
- How to format a UTC date as a `YYYY-MM-DD hh:mm:ss` string using NodeJS?
- JavaScript button onclick not working
- Invariant Violation: _registerComponent(…): Target container is not a DOM element
- How to count string occurrence in string?
- Angular 2 Hover event
- getElementsByClassName not working [duplicate]
- Javascript: Unicode string to hex
- Preloading images with jQuery
- socket.io – ReferenceError: io is not defined
- Object doesn’t support property or method ‘addEventListener’
- How to fix javascript .toFixed is not a Function error
- jQuery checkbox checked state changed event
- Javascript, viewing [object HTMLInputElement]
- Why onbeforeunload event is not firing
- etect the Enter key in a text input field
- Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (
) - Any advantage of using wp_scripts and is_IE when enqueuing scripts
- TinyMCE in a div / textarea on frontend?
- Include Javascript as Plain (No file inclusion)
- Adding wp_ajax to a theme outside functions.php (on specific template page)
- Insert shortcode in post editor from javascript (Visual / HTML)
- Provide specific example for block variation
- Block editor: How to check if block editor has initialized and populated the data store?
- Contact Form 7 – Give each checkbox a class?
- How to add a custom.js file for a child-theme in a swift way?
- is_page not working when loading javascript with add_action in functions.php
- var is undefined in a Gutenberg block
- Custom wp.editor.initialize settings ignored
- Why my javascript code not working for the dashboard of wordpress admin?
- Detect When User Reads Full Article? [closed]
- Got a TypeError after update and need to adapt found solution
- How to add classes and events to image in javascript using Gutenberg?
- Adding Code into Theme Customizer Header
- Javascript in wordpress
- How to inherit custom javascript from parent to child pages?
- Gutenberg – useEffect manipulate DOM after block re-renders DOM
- imporing HTML+javascript from REST API
- how to add a custom javascript file to our theme
- Why does my array sort order changes when I pass it to JS using WP_REST_Response?
- WordPress Guternberg Content For React Native
- Custom block update rendering when reused
- How do I add my own scripts to the add_action(‘wp_enqueue_scripts’) function?
- Post title and url not showing on google map marker [closed]
- Including js script at end of header
- contact form 7 javascript and wpcf7_before_send_mail action
- custom page url slug needs illegal ?id=1 for javascript
- Use one javascript variable into another javascript file
- Embed Kajabi into WP