# How to set username variable with current time as part of the username

**URL:** <https://community.postman.com/t/how-to-set-username-variable-with-current-time-as-part-of-the-username/44274>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [February 21, 2023, 1:22pm UTC](https://community.postman.com/t/how-to-set-username-variable-with-current-time-as-part-of-the-username/44274 "2023-02-21T13:22:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariannsz](https://avatars.discourse-cdn.com/v4/letter/m/cc9497/32.png) [@mariannsz](https://community.postman.com/u/mariannsz)\
**Post date:** [February 21, 2023, 1:22pm UTC](https://community.postman.com/t/how-to-set-username-variable-with-current-time-as-part-of-the-username/44274/1 "2023-02-21T13:22:59Z")

</div>

Hello! I’m new to Postman. I just received a collection with variables., but I need better custom usernames for my tests.  
Right now the Pre-request script looks like this:  
_pm.environment.set(“randomUserName”, ‘TestMUser’+currdate.valueOf())_

but I’m not happy with the usernames it makes, it doesn’t look like the current date at all, and overall too long, like this:  
TestMUser1676290156475,  
and I’d like it to be like this:  
TestMUser20230221999 or 21022023999

What can I do?  
Thank you in advance and please excuse my poor English.

---

<div class="post-metadata">

**Author:** ![arlem](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/arlem/32/3078_2.png) [@arlem](https://community.postman.com/u/arlem)\
**Post date:** [February 21, 2023, 2:09pm UTC](https://community.postman.com/t/how-to-set-username-variable-with-current-time-as-part-of-the-username/44274/2 "2023-02-21T14:09:55Z")

</div>

Hey there, welcome to the community! 👋

You can use Dynamic Variables to do that: [Dynamic Variables | Postman Level Up - YouTube](https://www.youtube.com/watch?v=vW030tA17ng)

Quick tip for next time, try searching the forum first as these questions typically have already been answered 😃

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [February 21, 2023, 2:24pm UTC](https://community.postman.com/t/how-to-set-username-variable-with-current-time-as-part-of-the-username/44274/3 "2023-02-21T14:24:35Z")

</div>

You can also use moment to format dates however you like.

Two examples…

```auto
const moment = require('moment');

let dateV1 = moment(new Date()).format("YYYYMMDD");
console.log("TestUser"+dateV1);

let dateV2 = moment(new Date()).format("YYYYMMDDssmmhh");
console.log("TestUser"+dateV2);

```

Version 2 includes the hours, minutes and seconds to ensure that its unique.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/a/fa320090dbdf8aaa02eb36b900f778c862a04d03.png)
