JsLearner
JsLearner

Reputation: 109

JavaScript : How do i set plus or minus 60 days daterange from today?

I need to pass startdate and enddate parameters to a webservice to fetch the response which range is from plus or minus 60 days from the current date. So what value i need to pass it in the StartDate and EndDate param of javascript? My Client Side App is build on JavaScript/AngularJs.

Upvotes: 2

Views: 480

Answers (3)

Zane Hitchcox
Zane Hitchcox

Reputation: 936

Unix timestamp version:

var currentUTC = new Date().valueOf()
var sixtyDays = 60*24*60*60*1000
var startDate = currentUTC - sixtyDays
var endDate = currentUTC + sixtyDays

Upvotes: 0

Tik
Tik

Reputation: 882

have a look at momentjs http://momentjs.com/ this is an excellent angular wrapper for moment https://github.com/gdi2290/angular-momentjs. always worth adding to your project when dealing with dates and times

Upvotes: 0

brso05
brso05

Reputation: 13222

You can do this:

var todaysDate = new Date();
var startDate = new Date();
var endDate = new Date();
startDate.setDate(todaysDate.getDate() - 60);
endDate.setDate(todaysdate.getDate() + 60);

Upvotes: 5

Related Questions