# Flows - need todays date as YYYY-MM-DD to use in If block

**URL:** <https://community.postman.com/t/flows-need-todays-date-as-yyyy-mm-dd-to-use-in-if-block/58128>\
**Category:** Help Hub\
**Tags:** variables, postman-flows\
**Created:** [February 26, 2024, 11:14am UTC](https://community.postman.com/t/flows-need-todays-date-as-yyyy-mm-dd-to-use-in-if-block/58128 "2024-02-26T11:14:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ah-potts](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@ah-potts](https://community.postman.com/u/ah-potts)\
**Post date:** [February 26, 2024, 11:14am UTC](https://community.postman.com/t/flows-need-todays-date-as-yyyy-mm-dd-to-use-in-if-block/58128/1 "2024-02-26T11:14:11Z")

</div>

Hi, i’m new to flows so aplogies if this is simple but i couldn’t see an answer anywhere.

As part of my flow, i need to use today’s date, as a string in format YYYY-MM-DD, as a variable in an If block. In the screenshot i need to replace “2024-02-26” with a varibale for current date  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/3/b353362988d8c586c6663ee3ea66f8a1a741b873.png)

I was able to set a global variable in a pre-request script for a GET API call using:  
const moment = require(‘moment’);  
pm.globals.set(“currentDate”, moment().format(“YYYY-MM-DD”));

However, it doesn’t appear that i can reference the global variable in the IF block and i can’t see how to set a local variable from the global.

Any help would be much appreciated  
Thanks  
Andrew

---

<div class="post-metadata">

**Author:** ![flows-daniel](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/flows-daniel/32/25516_2.png) [@flows-daniel](https://community.postman.com/u/flows-daniel)\
**Post date:** [February 27, 2024, 11:57pm UTC](https://community.postman.com/t/flows-need-todays-date-as-yyyy-mm-dd-to-use-in-if-block/58128/2 "2024-02-27T23:57:12Z")

</div>

Hi @ah-potts

Welcome to the forums!

Try this instead of your hard-coded string:

`$split($now(), 'T')[0]`

$now() will get you the full current date and time, splitting on T gives you just the date in the format you want.

Here’s a [link](https://learning.postman.com/docs/postman-flows/flows-query-language/data-manipulation/#get-the-current-time-in-iso-8601-format) to the docs how `$now` is used. I realize it was missing from our reference, so i’m going to add it there.

---

<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:** [March 28, 2024, 11:58pm UTC](https://community.postman.com/t/flows-need-todays-date-as-yyyy-mm-dd-to-use-in-if-block/58128/3 "2024-03-28T23:58:01Z")

</div>

Closed on March 28, 2024, 11:58pm UTC

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