-3

I have 2 dates: startDate= 6/22/2015 and endDate= 6/20/2015. I need to decrement these 2 dates, i meen endDate-startDate, so in this example I will get 2.

How can I do this in sql?

moshe
  • 29
  • 1
  • 7
  • You've mentioned both jquery and sql server in tags, so are you trying to subtract dates by jquery or by sql server? – Andrey Korneyev Jun 22 '15 at 10:50
  • Ah ok - you **don't mean** decrement, really - you mean find the **difference** (in days) between those dates - right? – marc_s Jun 22 '15 at 10:51
  • No, I need to decrement between them. What if the dates are: startDate= 6/29/2015, endDate= 7/2/2015? not just days. – moshe Jun 22 '15 at 11:03

1 Answers1

1

The native way to do this would be to use the setDate method. There is an existing Stackoverflow post here: How to Add Dates

However, I always pass along the advice to use a date library, something like moment.js. In most languages, managing dates (timezones, leap years, etc ets) is incredibly difficult, and javascript can be even more so with browser time zone behaviors.

Community
  • 1
  • 1
Brian
  • 1,513
  • 2
  • 14
  • 17