To convert the string to Date in JavaScript you can use the Date Object. JavaScript supports the following Date formats that can be used to convert the string to date: 

  • MM-dd-yyyy
  • yyyy/MM/dd
  • MM/dd/yyyy
  • MMMM dd, yyyy
  • MMM dd, yyyy

Following examples show the conversion of string to date using JavaScript Date Object:

Variable with Date Format as MM-dd-yyyy

var dateString = "03-20-2008";  
// MM-dd-yyyy

Variable with Date Format as yyyy/MM/dd

var dateString = "2008/03/20";  
// yyyy/MM/dd

Variable with Date Format as MM/dd/yyyy

var dateString = "03/20/2008";  
// MM/dd/yyyy

Variable with Date Format as MMMM dd, yyyy

var dateString = "March 20, 2008";  
// MMMM dd, yyyy

Variable with Date Format as MMM dd, yyyy

var dateString = "Mar 20, 2008";  
// MMM dd, yyyy

You can use any of the above date string formats that can be passed to the javascript Date Object:

var myDate = new Date(dateString);

document.write("Date :" + myDate.getDate());

document.write("<br>");

document.write("Month : " + myDate.getMonth());

document.write("<br>");

document.write("Year : " + myDate.getFullYear());

Continue to next tutorial: Javascript Day of Week Using Array to learn how to get the name of the week day using Javascript Date functions.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.