I'd like to know how to convert datetime mysql to date in JavaScript. I want to calculate a gap between 2 dates in seconds (get the gap number of seconds between 2 dates).
            Asked
            
        
        
            Active
            
        
            Viewed 525 times
        
    -1
            
            
        - 
                    would you atleast share expected output ? – Ravi Jan 23 '18 at 18:54
 - 
                    1I believe [this](https://stackoverflow.com/questions/3075577/convert-mysql-datetime-stamp-into-javascripts-date-format) is what you are looking for – F.Vilensky Jan 23 '18 at 18:54
 - 
                    It's kinda what I want yes – vinny Jan 23 '18 at 19:00
 - 
                    On the first day, just start counting slowly in your head, until the target day arrives – Strawberry Jan 24 '18 at 00:15
 
1 Answers
-1
            
            
        Please try following code:
let date1 = new Date("2017-12-21");
let date2 = new Date("2017-12-31");
let diffInSeconds = (date2.getTime() - date1.getTime())/1000;
console.log(diffInSeconds);
let date3 = new Date("2018-01-12 01:00:31");
let date4 = new Date("2018-01-12 02:30:32");
diffInSeconds = (date4.getTime() - date3.getTime())/1000;
console.log(diffInSeconds);
    
   
Hope it helps :)
        jasmin_makasana
        
- 472
 - 3
 - 11