Skip to content

Find the day of year from date in JavaScript

Advertisements

Find the day of year from date in JavaScript with the following code snippet.

const dayOfYear = (date) =>
  Math.floor((date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24);

dayOfYear(new Date());
//65
See also  How to add an element to an array in JavaScript?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.