# Compare date in body to date offset

**URL:** <https://community.postman.com/t/compare-date-in-body-to-date-offset/16639>\
**Category:** Help Hub\
**Tags:** variables, test\
**Created:** [October 10, 2020, 10:57am UTC](https://community.postman.com/t/compare-date-in-body-to-date-offset/16639 "2020-10-10T10:57:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![D4N13VT](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@D4N13VT](https://community.postman.com/u/D4N13VT)\
**Post date:** [October 10, 2020, 10:57am UTC](https://community.postman.com/t/compare-date-in-body-to-date-offset/16639/1 "2020-10-10T10:57:34Z")

</div>

I need to test that a date in the body “tokenExpiry” is at least 24 hours from now. My initial thought was to set an environment variable from which to compare, but I suspect there might be an easier way?

{  
“success”: true,  
“message”: “Authenticated”,  
“token”: {  
“token”: “abcde123”,  
“tokenExpiry”: “2020-12-09T10:46:59.7611225Z”  
}  
}

---

<div class="post-metadata">

**Author:** ![jeevananthank](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jeevananthank/32/4075_2.png) [@jeevananthank](https://community.postman.com/u/jeevananthank)\
**Post date:** [October 11, 2020, 11:36am UTC](https://community.postman.com/t/compare-date-in-body-to-date-offset/16639/2 "2020-10-11T11:36:13Z")

</div>

Hi!  
Welcome to the community!

Give a try with the below code.

```
var response = pm.response.json();
var tokenExpiry = response.tokenExpiry;
tokenExpiry = Date.parse(tokenExpiry);
var currentDate = new Date(Date.now());
var expectedDate = new Date(currentDate.setDate(currentDate.getDate() + 1));
expectedDate = Date.parse(expectedDate);
pm.expect(tokenExpiry).to.be.above(expectedDate);
```
