-5

I am trying to compare two dates as strings in typescript. The input I have is as below :-

startWindow = '05/2014'
endWindow = '05/2018'

I need to write a function to check if the start Window is greater than the end Window.

Both the inputs are of string type.

Thanks

nicael
  • 18,550
  • 13
  • 57
  • 90
gooner
  • 49
  • 4
  • 7
  • 3
    You keep getting downvotes because you asked people to write your code for you, rather than assist you in fixing the code that you've already written. The site is meant to help people who can't find the answers, not to do outsourced work for you. – maniak1982 Jul 25 '16 at 18:49
  • A string is not a proper way to work with dates. I suggest you to check this answer: http://stackoverflow.com/a/14781232/943082 (by Garry). First you should do the comparison, and then show the dates in the format that you want to display. Hope that it helps. – Guillermo Jul 25 '16 at 18:49
  • my bad guys... will take the advice into account when i post questions in future. – gooner Jul 25 '16 at 18:53

1 Answers1

2

You can convert it to a date and then compare them:

function convertDate(d)
{
 var parts = d.split('/');
 return new Date(parts[1], parts[0]);
}

var start = convertDate('05/2014');
var end = convertDate('05/2018');


alert(start < end);
nicael
  • 18,550
  • 13
  • 57
  • 90
kemiller2002
  • 113,795
  • 27
  • 197
  • 251