How to work with date format in jquery using moment JS ?

How to work with date format in jquery using moment JS ?

In this article, I will let you know how to work on date manipulation using Javascript jquery with moment library.

Date manipulation is very common process in every website and there are so many tools that you can use to change date format.

Date format can be like mm/dd/yyyy, mm-dd-yyyy, DD-MM-YYYY, yyyy-mm-dd etc.

Using Moment.js, you can easily resolve the issue for date and time format.

There are number of method available with Moment.js like you can add days to current date, subtract days or month from current date etc.

Syntax :
$(document).ready(function() {



This was the example to change date format. Now I will show you how you can add days, subtract days to current date :

moment().add('days', 2);    // adds 2 days to current date
moment().add('months', 2);  // adds 2 months to current date
moment().add('years', 2);   // adds 2 years to current date

Same you can try subtract() method :

moment().subtract('days', 2);   // subtracts 2 days to current date
moment().subtract('months', 2); // subtracts 2 months to current date
moment().subtract('years', 2);  // subtracts 2 years to current date
<!DOCTYPE html>
	<title>How to work with date format in jquery using moment JS?</title>
	<script type="text/javascript" src=""></script> 
    <script src=""></script>

<div class="container">
  <h2>Working on date manipulation:</h2>
    <li>Add : <span id="add_date"></span></li>
    <li>Subtract : <span id="subtract_date"></span></li>

    <li>Nov 17, 2018 : <span id="first_date"></span></li>
    <li>2018-11-17 : <span id="second_date"></span></li>
    <li>2018/11/17 : <span id="third_date"></span></li>


<script type="text/javascript">
  $(document).ready(function() {

    var add_day=moment().add('days', 2);

    var subtract_day=moment().subtract('days', 2);  

    var first_date = moment("Nov 17, 2018").format('DD-MM-YYYY');

    var second_date = moment("2018-11-17").format('DD-MM-YYYY');

    var third_date = moment("2018/11/17").format('DD/MM/YYYY');


Phone: (+91) 8800417876
Noida, 201301