# How to overcome timezone differences in two responses and compare them

**URL:** <https://community.postman.com/t/how-to-overcome-timezone-differences-in-two-responses-and-compare-them/23494>\
**Category:** Help Hub\
**Tags:** testscripts\
**Created:** [May 7, 2021, 5:36am UTC](https://community.postman.com/t/how-to-overcome-timezone-differences-in-two-responses-and-compare-them/23494 "2021-05-07T05:36:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harsha](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Harsha](https://community.postman.com/u/Harsha)\
**Post date:** [May 7, 2021, 5:36am UTC](https://community.postman.com/t/how-to-overcome-timezone-differences-in-two-responses-and-compare-them/23494/1 "2021-05-07T05:36:45Z")

</div>

I have two responses-response A and response B.  
response A has the below structure  
[{  
name:A  
age:B  
channel:[{  
date:“2018-07-23T00:00:00+02:00”,  
to:“2018-07-23T00:00:00+02:00”  
},  
{  
date:“2018-07-23T00:00:00+02:00”,  
to:“2018-07-23T00:00:00+02:00”  
}  
}]  
response B has the below structure  
[{  
name:A  
age:B  
channel:[{  
date:“2018-07-23T00:00:00.0+02:00”,  
to:“2018-07-23T00:00:00.002:00”  
},  
{  
date:“2018-07-23T00:00:00.0+02:00”,  
to:“2018-07-23T00:00:00.0+02:00”  
}  
}]

When I am trying to compare both the responses under test section in response B step, my test is failing as response B has “.0” extra. Please suggest how to overcome this?

Currently I am using deepcompare  
pm.expect(responseA).to.have.deep.members(resposneB)

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [May 7, 2021, 7:00am UTC](https://community.postman.com/t/how-to-overcome-timezone-differences-in-two-responses-and-compare-them/23494/2 "2021-05-07T07:00:50Z")

</div>

Hey @Harsha 👋

Maybe you can use `moment` to convert the timestamp to epoch timestamp and then compare (see below)?

```
const moment = require('moment')
let respA = [{
    date: '2018-07-23T00:00:00+02:00'
}]

let respB = [{
     date: '2018-07-23T00:00:00.0+02:00'
}]

respA.forEach((elem) => {
     elem.date = moment(elem.date).format('x')
})

respB.forEach((elem) => {
    elem.date = moment(elem.date).format('x')
})

pm.expect(respA).to.have.deep.members(respB)

```

Hope this helps! But let me know if you have any further questions 🙂

---

<div class="post-metadata">

**Author:** ![Harsha](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Harsha](https://community.postman.com/u/Harsha)\
**Post date:** [May 7, 2021, 2:29pm UTC](https://community.postman.com/t/how-to-overcome-timezone-differences-in-two-responses-and-compare-them/23494/3 "2021-05-07T14:29:04Z")

</div>

Thanks for the snippet @taehoshino  
Can you please suggest if the script will be working if I use the above snippet because in my original response I will have nearly 30 to 40 arrays of channel which has date inside it.

Also should I need to build a for loop inside channel ?

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [May 11, 2021, 5:14am UTC](https://community.postman.com/t/how-to-overcome-timezone-differences-in-two-responses-and-compare-them/23494/4 "2021-05-11T05:14:23Z")

</div>

Hey @Harsha! Thanks for your response!

You would need to make a small modification depending on the exact response, e.g.

```
const channels = pm.response.json().channel
channels.forEach((elem) => {
 elem.date = moment(elem.date).format('x')
})

```

Hope this helps!
