# Dynamic variable timestamp in milliseconds

**URL:** <https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [September 29, 2021, 1:36pm UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258 "2021-09-29T13:36:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tengl](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/tengl/32/9879_2.png) [@tengl](https://community.postman.com/u/tengl)\
**Post date:** [September 29, 2021, 1:36pm UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258/1 "2021-09-29T13:36:15Z")

</div>

Hi!

I would like to have a dynamic timestamp in milliseconds, eg. {{$timestampMs}}. [Dynamic variables | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/variables-list/)

What I do now is setting a variable in Pre-request Script

```js
pm.variables.set("timestampMs", new Date().getTime());

```

I don’t want to do that in every request i need a timestamp in ms.

I thought this would be a common case but I haven’t found any other requests for it.

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [September 29, 2021, 2:08pm UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258/2 "2021-09-29T14:08:48Z")

</div>

Unfortunately, there is no predefined Postman variable. But you can add this script to your collection and it will be available to all requests.

Each request will have a newly generated value.

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/0/0728e96a1df09227383f7d92785510b004491d10.png)

---

<div class="post-metadata">

**Author:** ![tengl](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/tengl/32/9879_2.png) [@tengl](https://community.postman.com/u/tengl)\
**Post date:** [September 30, 2021, 8:09am UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258/3 "2021-09-30T08:09:28Z")

</div>

Yes, thanks. That’s a bit better. A predefined variable would be preferable, but that will have to do.

---

<div class="post-metadata">

**Author:** ![samweow](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@samweow](https://community.postman.com/u/samweow)\
**Post date:** [May 12, 2023, 6:05pm UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258/4 "2023-05-12T18:05:52Z")

</div>

There is a pre-defined variable, you can access it like

```js
const timestamp = pm.variables.replaceIn('{{$timestamp}}')

```

---

<div class="post-metadata">

**Author:** ![maintenance-meteor12](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/maintenance-meteor12/32/26575_2.png) [@maintenance-meteor12](https://community.postman.com/u/maintenance-meteor12)\
**Post date:** [November 20, 2023, 4:30pm UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258/5 "2023-11-20T16:30:47Z")

</div>

> [@tengl](#):
>
> `pm.variables.set("timestampMs", new Date().getTime());`

Hi  
how to use in Body ?

---

<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:** [November 20, 2023, 4:40pm UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258/6 "2023-11-20T16:40:15Z")

</div>

Once a variable has been created and stored, it can be referenced in the body like this:

```json
{
    "time": "{{timestampMs}}"
}

```

---

<div class="post-metadata">

**Author:** ![maintenance-meteor12](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/maintenance-meteor12/32/26575_2.png) [@maintenance-meteor12](https://community.postman.com/u/maintenance-meteor12)\
**Post date:** [November 21, 2023, 8:27am UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258/7 "2023-11-21T08:27:40Z")

</div>

> [@danny-dainton](#):
>
> `"{{timestampMs}}"`

thank you Danny  
i have this body  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/9/394d46ba315c99cd51eb3d35600a6085e395840a.png)  
how to use  
1-“idRichiesta”: “00000062\_00000320\_1700497529”,  
2- “timestamp”: 1700497529,

---

<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:** [November 21, 2023, 9:10am UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258/8 "2023-11-21T09:10:01Z")

</div>

I don’t understand the question, how to use those where?

Do you want to extract those values from the request body and use them somewhere else?

You need to fully explain the use case and what you’re trying to achieve.

This should ideally be a separate question as this topic was already solved.

---

<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:** [November 21, 2023, 10:38am UTC](https://community.postman.com/t/dynamic-variable-timestamp-in-milliseconds/28258/9 "2023-11-21T10:38:24Z")

</div>


