0

If I have 2 strings in Typescript containing dates in this format

"17 October 2018 10:05 AM"

How can I convert them to Date types so I can compare them?

I had tried new Date(stringDate1) and moment(stringDate1) but they result in invalid dates obviously.

DarkW1nter
  • 2,933
  • 11
  • 67
  • 120
  • https://momentjs.com/docs/#/parsing/string-format/. But I really wonder why you have dates in such a format in the first place. Where does that string come from? Why doesn't this source use the ISO format? – JB Nizet Oct 17 '18 at 16:04
  • just what I need, thanks – DarkW1nter Oct 17 '18 at 16:05
  • https://stackoverflow.com/a/45330707/495157 https://angular.io/api/common/DatePipe – JGFMK Oct 17 '18 at 16:12
  • Be aware, adding moment.js in Angular adds a ton of weight to your application. If all you need to do is create a Date object from this string, I would consider simply breaking the string apart and creating the date object that way. – Brandon Taylor Oct 17 '18 at 16:14

0 Answers0