{"id":1363,"date":"2014-06-21T00:09:16","date_gmt":"2014-06-21T00:09:16","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=1363"},"modified":"2014-06-21T00:18:23","modified_gmt":"2014-06-21T00:18:23","slug":"how-to-add-days-in-a-date-string-using-javascript","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2014\/06\/how-to-add-days-in-a-date-string-using-javascript\/","title":{"rendered":"How to add days in a date string using JavaScript ?"},"content":{"rendered":"<p>This is how you can add number of days in a date string using JavaScript.<br \/>\nIn this example i have added 6 days in a date. Please check the demo.<\/p>\n<pre lang=\"js\">\r\n\tvar someDate = new Date(\"2014-06-20\");\r\n\tvar numberOfDaysToAdd = 6; \/\/ add 6 days\r\n\tsomeDate.setDate(someDate.getDate() + numberOfDaysToAdd);\r\n\r\n\tvar dd = someDate.getDate();\r\n\tvar mm = someDate.getMonth() + 1;\r\n\tvar y = someDate.getFullYear();\r\n\r\n\tvar someFormattedDate = y +'-'+ mm +'-'+dd;\r\n\/\/ output 2014-06-25\r\n<\/pre>\n<p>Another example using php.<br \/>\nYou can add any number of days if you want to reduce number of days use minus(-) sign instead.<\/p>\n<pre lang=\"php\">\r\n<?php\r\n$date = \"2014-06-20\";\r\n$date = strtotime($date);\r\n$date = strtotime(\"+6 day\", $date);\r\necho date('M d, Y', $date);\r\n?>\r\n<\/pre>\n<p><a href=\"http:\/\/jsfiddle.net\/phpmind\/TBTR2\/\" target=\"_blank\"><\/p>\n<h2>Demo<\/h2>\n<p><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is how you can add number of days in a date string using JavaScript. In this example i have added 6 days in a date. Please check the demo. var someDate = new Date(&#8220;2014-06-20&#8221;); var numberOfDaysToAdd = 6; \/\/ add 6 days someDate.setDate(someDate.getDate() + numberOfDaysToAdd); var dd = someDate.getDate(); var mm = someDate.getMonth() + [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[27],"tags":[],"class_list":["post-1363","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=1363"}],"version-history":[{"count":9,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1363\/revisions"}],"predecessor-version":[{"id":1372,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/1363\/revisions\/1372"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=1363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=1363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=1363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}