Back to Top

Convert date from one format to another format using javascript

convert date from one format to another format using javascript

Here is the quick article about to convert date from one format to another format in Javascript.Recently I am working on one functionality and want to convert javascript date and I have an input date as string in format dd/MM/yyyy now I want to convert it into Date object having format yyyy-MM-dd with time.

Must Read: Convert 12-hour datetime to 24-hour datetime in JavaScript

Let’s see the function:

function convert_date_format(date_input)
{
    var split_space = date_input.split(' ');
    var date_part = space[0];
    var date_explode = date_part.split('-');
    var new_date = date_explode[2]+'-'+date_explode[1]+'-'+date_explode[0]+' '+space[1];
    return new_date;
}

Here I have extracted the date and time with split function then again split date part with split function and then combine the exploded part and create your own format of the date.

Also Read: To convert DATE in other language in PHP

That’s it. I hope that you find this tutorial useful to someone.

Don’t hesitate to use this code in your projects and post your comments if you need help. As always, thanks for reading. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

How to Use PHP Sessions to Store Data

Posted on 2 years ago

Bhumi

Fixed Remove class issue with MooTools

Posted on 7 years ago

Bhumi

How to Get local time using EarthTool

Posted on 6 years ago

Bhumi

Cursor in IndexedDB API HTML5

Posted on 4 years ago

Bhumi

Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago

Bhumi

ECMAScript 6 New Features – 2

Updated 1 year ago

Bhumi

The Reader’s Poll – June 2015

Posted on 4 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 5 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 5 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 6 years ago

Bhumi