Friday, September 19, 2025
HomeLanguagesJavascriptD3.js | d3.utcDay() Function

D3.js | d3.utcDay() Function

The d3.utcDay() function in D3.js is used to return date in “YYYY-MM-DD” format in Coordinated Universal Time (UTC).

Syntax:

d3.utcDay(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.utcDay() 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.utcDay()
        var day = d3.utcDay(now);
  
        // Getting the date
        console.log(day);
    </script>
</body>
  
</html>


Output:

"2019-07-20T00:00: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 utcDay() function to
        // calculate the difference between two dates
        var a = d3.utcDay.count(start, end);
  
        // Getting the calculated dates
        console.log(a);
    </script>
</body>
  
</html>


Output:

3
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32301 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6666 POSTS0 COMMENTS
Nicole Veronica
11840 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11898 POSTS0 COMMENTS
Shaida Kate Naidoo
6781 POSTS0 COMMENTS
Ted Musemwa
7056 POSTS0 COMMENTS
Thapelo Manthata
6739 POSTS0 COMMENTS
Umr Jansen
6745 POSTS0 COMMENTS