Check format date with Postman

Hello :slight_smile:

I want to create a test that validates if the date format respects this: YYYY-MM-DD

in the body I have this answer:

β€œdate”: β€œ2021-10-29”

help me please

@mld1954 Welcome to the community :partying_face:

Please refer the similar post discussed here.

Something like below would work too:

var jsonData = pm.response.json();
console.log(jsonData.data)

let date = jsonData.data;

let moment = require ('moment');

pm.test("Checking data format", function () {
    pm.expect(date).to.include(moment(date).format('YYYY-MM-DD'));
});
1 Like

Thank you very much @bpricilla :slight_smile:

1 Like