Thursday, June 11, 2026
HomeLanguagesJavascriptD3.js | d3.timeDay() Function

D3.js | d3.timeDay() Function

The d3.timeDay() function in D3.js is used to return date in “YYYY-MM-DD” format.

Syntax:

d3.timeDay(Date);

Parameters: This function accepts a parameter “Date”.

Return Value: This function returns the given date in a specific format.

Below programs illustrate the d3.timeDay() function in D3.js:
Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <script src=
        "https://d3js.org/d3.v4.min.js">
  </script>
</head>
  
<body>
  
    <script>
        // Initialising a current date
        var now = new Date;
  
        // calling d3.timeDay()
        var day = d3.timeDay(now);
  
        // Getting the date
        console.log(day);
    </script>
</body>
  
</html>


Output:

"2019-07-19T18:30:00.000Z"

Example 2: Below code calculates the difference between two given dates.




<!DOCTYPE html>
<html>
  
<head>
    <script src=
            "https://d3js.org/d3.v4.min.js">
  </script>
</head>
  
<body>
  
    <script>
        // Initialising start and end date
        var start = new Date(2015, 02, 01);
        var end = new Date(2015, 02, 04);
  
        // Calling the timeDay() function to
        // calculate the difference between two dates
        var a = d3.timeDay.count(start, end);
  
        // Getting the calculated dates
        console.log(a);
    </script>
</body>
  
</html>


Output:

3
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS