How to Add Seconds to a Date in TypeScript

TypeScript add seconds to date: Command Prompt output of an addSeconds helper using getTime

The cleanest way to add seconds to a date in TypeScript is to read the timestamp with getTime(), add the seconds times 1000, and wrap the sum in a new Date. Your original date isn’t touched: I ran every snippet here with TypeScript 7.0.2 and Node.js v22.22.2 in strict mode, so the printed results are … Read more >>

How to Convert Dates to UTC in TypeScript?

Date to UTC conversion in TypeScript

I was recently working on a feature that needed to sync date and time data across users in different time zones. There, I noticed that times were showing up inconsistently depending on where the user was located. In that situation, I had to convert all dates to UTC (Coordinated Universal Time) to keep the date … Read more >>

Format Dates in TypeScript as YYYY-MM-DD

Formatted date in TypeScript using YYYY-MM-DD format

When working with dates in TypeScript, formatting them into a readable or standardized structure is often necessary, especially for storing in databases or displaying in user interfaces. One of the most common formats used in web development is YYYY-MM-DD, which ensures consistency across systems and locales. In this tutorial, you’ll learn to format dates in … Read more >>

How to Calculate Days Between Two Dates in TypeScript

Days between dates in TypeScript: VS Code showing a day count across daylight saving time fixed with Date.UTC

Counting days between dates in TypeScript takes one line: subtract the two getTime() values and divide by 86,400,000, the number of milliseconds in a day. Wrap it in Math.round() so a daylight saving shift can’t leave you with 13.96 days: In this tutorial, we’ll count the days between dates in TypeScript the safe way, from … Read more >>

Extract Year From Date in TypeScript

Extract year from specific date in TypeScript

Have you ever worked on a feature where you needed to group records by year? I recently faced this while building an internal dashboard using TypeScript for tracking employee onboarding. I was working on an employee management module built with TypeScript, where each employee’s joining date was stored in the system. My task was to … Read more >>

How to Add Minutes to a Date in TypeScript?

Update date by adding minutes in Typescript

While working on a feature to send timed reminders, I needed to add a few minutes to a given date in my TypeScript app. For this, I first tried using the built-in setMinutes method, but soon realized it could lead to issues when reusing the original date object. I explored other approaches to avoid this … Read more >>

How to Handle ISO Date Strings in TypeScript?

Convert ISO format to Date in Typescript

While working on a recent feature that displayed important dates in a user-friendly format, I encountered an issue. The ISO date string, like “2025-07-04T00:00:00.000Z,” was showing up as July 3 instead of July 4 in the UI. At first, it seemed like a simple formatting issue, but it turned out to be a classic time … Read more >>

Convert Number to Date in TypeScript

Convert Number to Date in TypeScript with Unixtime stamp

When I was working on a TypeScript project recently, I got a requirement to show dates from a system that sent me big numbers like 1623456789000. These numbers are called timestamps, and they represent a date and time, but in a format that’s hard to read. In this blog, I will show you how to … Read more >>

How to Check for Invalid Dates in TypeScript?

Check invalid dates in typescript

Have you ever seen your app behave strangely just because someone entered the wrong date? For example, a user might type “2025-02-30”, which is not even a real date or the used date format is not valid for the app’s date settings. These small issues can cause big problems if we don’t handle them properly. … Read more >>

How to Subtract Dates in TypeScript (With Examples)

TypeScript subtract dates: Command Prompt output breaking a date difference into days, hours and minutes

Subtracting dates in TypeScript comes down to one move: call getTime() on both Date objects and subtract the numbers. The result is the gap in milliseconds, which you divide down to seconds, hours or days. Writing end – start directly won’t compile in TypeScript: In this tutorial, we’ll subtract dates in TypeScript step by step. … Read more >>