Assertion without decimals -- How to Remove a decimal value from a String?

How to Remove a decimal value from a String?

var Date_time = β€œ2023-01-05T03:57:46.4506857+00:00”;

what I want = β€œ2023-01-05T03:57:46+00:00”;

This can be done using the JavaScript split method.

let before = "2023-01-05T03:57:46.4506857+00:00";
let after = before.split(".")[0];

console.log(before);
console.log(after);

image

Still getting assertion error – AssertionError: expected β€˜2023-01-05T03:57:46+00:00’ to deeply equal β€˜2023-01-05T03:57:46’

Can you post your code for the assertion? (please use the preformatted text option in the editor).

let orignal = "2023-01-05T03:57:46.4506857+00:00";
let actual = "2023-01-05T03:57:46+00:00";
let expected = orignal.split(".")[0];

console.log(orignal);
console.log(expected);

pm.test("Validation", function () {
    var jsonData = pm.response.json();
    pm.expect(expected).to.eql(actual);
    

});

This is dirty, there might be a better way using regex.

let original = "2023-01-05T03:57:46.4506857+00:00";
let actual = "2023-01-05T03:57:46+00:00";
let expected = original.split(".")[0] + "+" + original.split("+")[1];

console.log(original);
console.log(expected);

pm.test("Validation", function () {
    pm.expect(expected).to.eql(actual);
});

On a side note, what are you actually trying to assert. Do you really care about the 00:00? You could just use split on the plus sign for the actual as well and that would make both the same format.

Another option is to use something like the moment library (which is included in Postman) to format both dates to yyyymmddhhmmss which means its just a number comparison after that.

It’s working… thanks