1

I'm reading a file's modification date with fs.statSync() and I'd like to compare it with a String that comes from my database:

This is my file's last modification date:

Fri Mar 24 2017 13:22:01 GMT+0100 (Central Europe Standard Time)

And I'd like to compare with this string:

2016-07-18 12:28:12

How can I do this with Node.JS? Can I somehow create a new date from the String?

1 Answer 1

1

You can use Moment parse both of those formats and compare the results.

var date1 = moment(string1, format1, true);
var date2 = moment(string2, format2, true);
if (date1.diff(date2) === 0) {
    // equal
} else {
    // not equal
}

See this answer for parsing dates in different formats:

Make sure that you parse it with explicit format and you don't let it guess the format, or otherwise you will never be sure if it guessed correctly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.