Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare two dates in Angular 6

I am new to angular 6 ,Here I need to compare to date inputs and find the greatest one.

input 1 : 2018-12-29T00:00:00
input 2 : Mon Dec 31 2018 00:00:00 GMT+0530 (India Standard Time)

Here I received the input 1 from mssql database and the input 2 from the material datepicker .

while compare this two dates as below I got false.

console.log(mMagazineObject.From < mMagazineObject.To ? true : false);

is there any possibility to compare these two date formats .If yes please help me to fix this .

like image 690
Zhu Avatar asked Jan 01 '19 14:01

Zhu


1 Answers

you can use getTime

if (input1Date.getTime() < input2Date.getTime()) 

Note that if your dates are in string format, you first need to parse them to Date

like image 94
Derviş Kayımbaşıoğlu Avatar answered Sep 22 '22 08:09

Derviş Kayımbaşıoğlu