-1

I'm trying to get the difference between the 2 dates in googlescript. However it doesn't seem to be working. Does anyone seem to know why? My user defined variables are working it's just when i get the difference between the 2 the result is like 4.28E8 whereas the answer is supposed to be like 40. Is there a way to convert the date into a number then convert it back into a date?

 ddate = output.getRange(lRow2,2,1,1).getValue() - output.getRange(2,1,1,1).getValue()
xndr
  • 523
  • 1
  • 9
  • 19
  • When you subtract two dates you get the difference in ms. 4.28E8 ms = 119 hours. – SpiderPig Apr 28 '15 at 03:24
  • Search for posts like this: [stackoverflow - javascript - difference between two dates](http://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript) – Alan Wells Apr 28 '15 at 04:18
  • oh ok. so just convert it to hours. Thanks, @SpiderPig – xndr Apr 28 '15 at 05:03

1 Answers1

1

Function works, its just the difference is in milliseconds. For those interested in the conversion, it's as follows:

diff = ((output.getRange(lRow2,2,1,1).getValue() - output.getRange(2,1,1,1).getValue()) / (1000*60*60*24))

or simply:

days = milliseconds/ (1000*60*60*24)

xndr
  • 523
  • 1
  • 9
  • 19