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=
</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=
</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