Date Format response No match?

Hi,
I’m testing the format of this value “date” but unfortunately I received this.
Do you have any suggestions?
These are the elements:

Request POST Body

{
“key”: “value”,
“date”: “2017-07-21T17:32:28Z”,
“key”: “value”,
“key”: “value”,
“key”: “value”,
“key”: “value”
}

Test GET

const jsonData = pm.response.json();
pm.test(“date is in the correct format”, function () {
pm.expect(jsonData.date).to.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/);
});

GET response

“date is in the correct format | AssertionError: expected ‘2017-07-21 17:32:28+00:00’ to match /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/”

Thanks!

The value in your request is an ISO date with UTC (which is what the Z on the end means).

For some reason, the assertion is changing it to relative time. (+00:00) which then fails your regex.

Can you double check the response and ensure the API hasn’t changed the date format.

Also have a look here for some other regex’s that you might want to consider.

regex to verify UTC date time format - Stack Overflow

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