# Date generation for the first day of the next month

**URL:** <https://community.postman.com/t/date-generation-for-the-first-day-of-the-next-month/59571>\
**Category:** Help Hub\
**Tags:** pre-request-script\
**Created:** [April 4, 2024, 8:06am UTC](https://community.postman.com/t/date-generation-for-the-first-day-of-the-next-month/59571 "2024-04-04T08:06:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![berson](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/berson/32/27933_2.png) [@berson](https://community.postman.com/u/berson)\
**Post date:** [April 4, 2024, 8:06am UTC](https://community.postman.com/t/date-generation-for-the-first-day-of-the-next-month/59571/1 "2024-04-04T08:06:22Z")

</div>

Hi all.

How can I generate a date for the first day of the next month from the specified one.

For example, the current date is 20.03.2024 (from the global variable)  
The next date is 01.04.2024

For example, the current date is 03.04.2024 (from the global variable)  
The next date is 01.05.2024

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [April 4, 2024, 10:41am UTC](https://community.postman.com/t/date-generation-for-the-first-day-of-the-next-month/59571/2 "2024-04-04T10:41:16Z")

</div>

Hey @berson 👋

I’m sure there are more efficient ways to do it but given the format you’re using and the output you want to see:

```auto
let d = new Date("2024.05.04");
d.setMonth(d.getMonth() + 1, 1);

console.log(d.toLocaleDateString('en-GB').replace(/[\s/]+/g, '.'));

```

That might work for you.

---

<div class="post-metadata">

**Author:** ![berson](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/berson/32/27933_2.png) [@berson](https://community.postman.com/u/berson)\
**Post date:** [April 4, 2024, 11:10am UTC](https://community.postman.com/t/date-generation-for-the-first-day-of-the-next-month/59571/3 "2024-04-04T11:10:54Z")

</div>

Yes, that’s great.

I want to make a format d.format(YYYY-MM-DD);  
but it’s dont’t work

```auto
let d = new Date("2024.05.04");
d.setMonth(d.getMonth() + 1, 1);

console.log(d.format(YYYY-MM-DD);

```

add: 14\_47

It’s work!

```auto
let d = new Date("2024.05.04");
d.setMonth(d.getMonth() + 1, 1);

console.log(d.toISOString().substring(0, 10));

```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [April 4, 2024, 1:05pm UTC](https://community.postman.com/t/date-generation-for-the-first-day-of-the-next-month/59571/4 "2024-04-04T13:05:33Z")

</div>

Cool, are you all set now? 🙏

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [April 7, 2024, 1:06pm UTC](https://community.postman.com/t/date-generation-for-the-first-day-of-the-next-month/59571/5 "2024-04-07T13:06:16Z")

</div>

Closed on April 7, 2024, 1:06pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
