question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding a month appears to be adding 30 days?

See original GitHub issue

This code in ts-node:

import { add } from 'date-fns';

let date = new Date('2020-07-01');
console.log(date);

let next = add(date, { months: 1 });
console.log(next);

Outputs the following:

2020-07-01T00:00:00.000Z
2020-07-31T00:00:00.000Z

When adding 1 month, my expectation was that 07-01 would become 08-01. What am I missing here? Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
SonofNun15commented, Sep 15, 2021

Actually it was as simple as setting the timezone to utc for the node process. Thank you so much for your help!

process.env.TZ = 'UTC';
1reaction
SonofNun15commented, Sep 15, 2021

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add or subtract dates - Microsoft Support
Add or subtract days, months, or years from a date by using a formula or date functions in Excel.
Read more >
Date Calculator: Add to or Subtract From a Date
Enter a start date and add or subtract any number of days, months, or years. ... See how long remains before a deadline...
Read more >
How to add and subtract dates in Excel - Ablebits
See how to quickly subtract or add two dates, add days to a date, add or subtract weeks, months and years, and calculate...
Read more >
How to Add Months to or Subtract Months From a Date in Excel
Download the featured file here: https://www.bluepecantraining.com/how-to- add - months -to-or-subtract- months -from-a-date-in-excel/In this ...
Read more >
How to Add Days to Dates in Excel - YouTube
In this video we look at 3 different ways to add or subtract days to dates in Excel using formulas, copy & paste,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found