Thursday, October 23, 2025
HomeLanguagesJavascriptHow to remove time from date using JavaScript ?

How to remove time from date using JavaScript ?

Given a Date Object and the task is to remove the time portion from the object using JavaScript

JavaScript split() Method: This method is used to split a string into an array of substrings, and returns the new array. 

Syntax:

string.split( separator, limit )

Parameters:

  • separator: This parameter is optional. It specifies the character or the regular expression to use for splitting the string. If not used, the whole string will be returned (an array with only one item).
  • limit: This parameter is optional. It specifies the integer that specifies the number of splits, items beyond the split limit will be excluded from the array.

Return value: It returns a new array, having split items. 

Example 1: This example splits the date by using (‘ ‘) and then takes the value at index = 0 of the array returned after split using split() method

Javascript




let d = '12/05/2019 12:00:00 AM';
 
console.log(d.split(' ')[0]);


Output

12/05/2019

Example 2: This example is quite similar to the previous one. This example first splits the date by using (‘ ‘) and then take the value at index = 0 of the array returned after split using split() method. It works with Date objects. 

Javascript




let d = new Date();
         
console.log(d.toISOString().split('T')[0]);


Output

2023-06-14
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS