I have issue when compare the two strings (both are variable meaning it could be any dates) The format of those two strings are yyyy-MM-dd.
I have two strings dates "string1" and "string2", and string1 one using date format yyyy-MM-dd and string 2 using the same format yyyy-MM-dd. What should I use if I want to compare it with the logic when string1 < string2 return string result as "X"
What I current have which not working first I try to use .substring to get the right format from string 1.
var string1 = str1.substring(0, 5) + str1.substring(5, 8) + str1.substring(8, 11);
var string2 = str2
if (string1 < string2) {
dateresult= 'X';
}
Any idea will be appreciated.
Thanks in advance.




yyyy-MM-ddthen you can just do a<comparison on them directly and it should work, because even though that's a lexical string comparison, with dates in that format lexical string order is also date order. Your thing with the.substring()is pointless - it simply extracts the first 10 characters of the original string in three parts but then puts them back together in the same order (unless your original input had more characters after the date?).str1andstr2.)str1.substring(0, 5) + str1.substring(5, 8) + str1.substring(8, 11)?str1.slice(0,11)is shorter.