Categories
JavaScript Answers

How to set just the date, ignoring time with JavaScript Date?

Spread the love

Sometimes, we want to set just the date, ignoring time with JavaScript Date.

In this article, we’ll look at how to set just the date, ignoring time with JavaScript Date.

How to set just the date, ignoring time with JavaScript Date?

To set just the date, ignoring time with JavaScript Date, we pass in a date string into the Date constructor.

For instance, we write

const newDate = new Date(oldDate.toDateString());

to get the oldDate‘s date as a string with toDateString.

Then we pass that into the Date constructor to create a new date object with the date.

Conclusion

To set just the date, ignoring time with JavaScript Date, we pass in a date string into the Date constructor.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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