Skip to content
Related Articles

Related Articles

How to extract date from a string in dd-mmm-yyyy format in JavaScript ?

View Discussion
Improve Article
Save Article
  • Last Updated : 09 Dec, 2020

In this article, we will see how to extract date from a given string of format “dd-mmm-yyyy” in JavaScript. We have a string, and we want to extract the date format “dd-mmm-yyyy” from the string.


// String
str = "India got freedom on 15-Aug-1947"

// Extracted date from given string in 
// "dd-mmm-yyyy" format
date = 15-Aug-1947


  • There is no native format in JavaScript for” dd-mmm-yyyy”. To get the date format “dd-mmm-yyyy”, we are going to use regular expression in JavaScript. 
  • The regular expression in JavaScript is used to find the pattern in a string. So we are going to find the “dd-mmm-yyyy” pattern in the string using match() method.
  • Syntax:




<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" 
    <!-- div element -->
    <div style="color: red;
        background-color: black;
        margin: 80px 80px;
        padding: 40px 400px;">
        India got freedom on 15-Aug-1947.
            Click the button to see date
    <!-- Link of JQuery cdn -->
    <script src=
        // After clicking the button it will 
        // show the height of the div
        $("button").click(function () {
            // String that contains date
            var str = "India got freedom on 15-Aug-1947"
            // Find "dd-mmm-yyyy" format in the string
            var result =
            // Show date on screen in 
            // format "dd-mmm-yyyy"

Before clicking the button:

After clicking the button:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!