DEV Community

JavaScript Date Guides

JavaScript date objects, like many other things in JavaScript, can be tricky. Dates, in general, can be tricky. Thankfully we have a lot of great guides here.

This is a collection of top and trending guides written by the community on subjects related to JavaScript Date concepts. For all things JavaScript, check out the JavaScript tag! Please contribute more posts like this to help your fellow developer in need.

Styling a native date input into a custom, no-library datepicker

For Helppo users, I wanted to offer a way to edit date and datetime values more conveniently than with a plain text input. This is of course nothing new; most sites use datepickers for this purpose.


How to mock Date with Jest

I spent too many hours trying to mock correctly the JavaScript's Date object. I tried a few things I've found on Google... without success. I finally ended up with a kinda handcrafted solution.


How to query documents in MongoDB that fall within a specified date range using Mongoose and Node.

You're meant to build a date range component that sends the startDate and the endDate to the backend. I won't go through building this as our concern is how to handle using dates on the backend to query the database. The point here is to define what values we're expecting as request parameters for the query.


JavaScript format Date as YYYY-MM-DD

But be careful! This result based on UTC date and time.


You might not need date-fns

Hola! Lazy dev here and today we are going to discuss date-fns. People often choose date libraries before they really need it. "How we will format the date?", "Are there any alternatives?"


Formatting and modifying JavaScript dates with date-fns

There are currently two big players when it comes to JavaScript libraries for date management. MomentJS and Date-FNS.


A Good React Date and Time Picker

There are so many date pickers out there, but I can't find one that


Date Handling in Angular Application (Part 1 — JSON and JavaScript Date Object Study)

https://medium.com/self-learning/date-handling-in-angular-application-part-1-json-and-javascript-date-object-s-8f77a69734c7


3 Efficient ways to get tomorrow date using javascript

In this article, we will see some of the efficient ways to get tomorrow date using javascript.


Create your Live Real Time Clock and Date in "React.js", no 3rd Party Hassle

Have you worked on a project and you wanted to display the date and time live maybe in your navbar or something?


Ways to convert string to date in Javascript

A string date can be of three types and, we will convert each of those to a date object in javascript.

Formats of string date:


A Complete Guide to JavaScript Dates (and why your date is off by 1 day)

Don’t worry, I’m not some JavaScript purist here telling you to always work with vanilla JS Date Objects — I just want to work through the core concepts that will make your life with Moment/Luxon much much easier.


Vanilla JavaScript Check if Date is in the Past

See the Pen
Vanilla JavaScript Check if Date is Past
by Chris Bongers (@rebelchris)
on CodePen.


Javascript Age Calculator | Calculate Age from Date of Birth

JavaScript Age Calculator helps to determine user's current age from date of birth. This is a very easy and simple design. I have shared many more designswith you before. This is the first time I've made a simple JavaScript age calculator and shared it with you.


Temporal - Date & Time in JavaScript today!

Every developer at some point in their careers had to play with Date & Time and if you are lucky... You only had to deal with time zones when you are travelling.


Format Date and Time with Vanilla JavaScript

I've used a variety of tools over the years to manage date and time functionality in JavaScript. Here I am documenting the Vanilla JavaScript patterns for my own use.


Using an expiry date in JavaScript to create self-destructing data

For this tutorial, I'm going to use the context of an application I built with React that provides the user with a meditation timer, a focus/pomodoro timer, and a home and landing page featuring the date and time, local weather, and an inspiring quote of the day.


How to Add a Date Picker to Your Vue App

For many applications, recording dates is an important feature. Having date picker inputs is often a handy feature to have. Fortunately, many developers have made date picker components that other developers can easily add to their apps.


How to check for missing, unused, or out-of-date JavaScript dependencies

Managing dependencies is very important to developing and maintaining a JavaScript application. Here are three quick tips to help with checking for missing, unused, or out-of-date dependencies!


Digital Clock with Date using JavaScript, Html & CSS

Watch the live demo to see how this digital clock works. Digital clock are much more beautiful and much easier to make. If you know the basic HTML CSS and JavaScript programming code, you can easily build a digital clock.

Basically I made this watch based on JavaScript programming code. Very little HTML and CSS code has been used. In this digital clock you will see everything from time to date months. First of all you will see the time here with the option of AM / PM.


Get Real Time Date and Time using JavaScript

So our topic is Get Real time date and Time using JavaScript. Real time date and time is same time and date that we see at our computer,mobile or watch screen. We just once set the time on our devices and they gave us updated time whenever we see.

So the question is how can we see such Real time date and Time on our web page.

Let’s get this...

First we will create a demo page using HTML and CSS to visualize how our time and date will look like...let’s create a beautiful demo page.


Perfectly localizing date & time with Intl.DateTimeFormat

These attributes define how to format each part of the date individually.


Javascript Date String Parsing

One of my favorite features of PHP is the strtotime function. This function lets you pass in a date string and have a unix timestamp returned


A Guide to Handling Date and Time for Full Stack JavaScript Developers

Time plays an essential role in our lives. Therefore, as developers we get to work with date and time quite frequently. Computer software is used by people from anywhere in the world and the time in one region can differ from the time in another region. And, generally in the software we build we capture and process the date and time of various data records and events. Therefore, it's important to understand various nuances around working with date and time.


Add days to a Date in vanilla JavaScript

Despite the JavaScript Date warts, it’s straightforward to add days to a date in JavaScript.


Creating a custom date-time picker using Angular Material

My requirement was very specific so I am going to talk in terms of mm/dd/yyyy, hh:mm:ss input field format i.e. in the same field you must be able to edit date and time and also choose a calendar view with time fields as well besides date.


Working with date locale in your Cypress test

I recently came across a challenge when working with date locale's especially within the browser, and sometimes it could be very challenging there is a quick way around this using the Intl.DateTimeFormat() more info


Customizing Vanilla JS Date & Date Range Picker

I recently needed a javascript date range picker component for ShareTXT. I required something which when clicked on would produce a dropdown menu consisting of fixed date ranges (Last 7 days, Last 30 days etc.) which users could click to analyse the data between that range without having to manually enter the dates into the component. I wanted the component to be easily extended and customized to match the website theme.


Introducing a handy JavaScript date formatting function.

I created A function to format the date (Date object) with a pattern like yyyy-MM-dd'T'HH:mm:ssXXX in JavaScript.

With this function alone, ISO8601 format, RFC1123 format, time zone RFC822, etc. can be expressed.

Pattern specification is like Java's SimpleDateFormat.


DayJS: Awesome lightweight modern Date API and an alternative to MomentJS

DayJS is a lightweight JavaScript date API (2kB) which describe the same MomentJS API. (If you use Moment.js so could use easily Day.js )


Mock Intl and Date globals in Jest (easily!)

Now to test this, we'll need to mock out both the Intl and Date Javascript globals. We can do this using Jest's spyOn method to temporarily replace the global method with our own implementation. Notice that we setup the spy in the beforeEach and reset everything in the afterEach. The setup works something like this:


Javascript Date & Time Cheatsheet(Moment.js, Day.js, date-fns)

Link: Javascript Date & Time Cheatsheet


Keep your NPM dependencies up to date with npm-check

Including this tool can be very quick, and this is a real time savior for the future. Keeping your dependencies up to date may lead in quicker micro improvements that could bring more value if you use it for larger projects.


How to count occurrences of dates in an array of date ranges: JavaScript

I have a date-range of 01-01-2020 to 31-12-2020 and an array of date-ranges. I want the occurrence of each date in the array vs the main range.


Disabled Dates Pikaday Date Picker

One feature that we've been talking about for some time now, but has taken a back seat while the mobile app was being built / tested / updated, is to update our date picker to block off days where charters are unavailable. Our date picker was used as a custom livewire component that is powered by pikadays lightweight javascript date picker. That particular component is used throughout our web app but on the individual charters listing page is where we need to "block" dates on the picker so that if a captain has a booking, or has blocked it off on the web or mobile app, we need it to reflect our date picker, so that we can have a more accurate availability.


✨♻️One line - Date Operations in JavaScript

Check if a date is before another date.


Top Date Picker JavaScript Plugins and Libraries

Select menus are a common choice for date pickers since they’re easy to set up. But after decades of using MM/DD/YY menus, I think our users deserve better.


Javascript Format Date without Moment.js (Eg: 17 July, 2021 )

Almost everyone like me might be using the plugin moment.js to format a date-time-stamp to a readable date or time - Eg: 14 July 2021 or 11:58 pm


Format Time and Date Relatively with JavaScript

Format Date and Time with JavaScript


Format Date and Time with JavaScript

The Intl object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting.


Adding days to a date using Vanilla JS

Despite the JavaScript Date warts, it’s straightforward to add days to a date in JavaScript.


Happy JavaScript Date coding!