Friday, September 5, 2025
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
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11861 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6699 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS