Moment.js - get start of day yesterday

SiemensSEN
SiemensSEN used Ask the Experts™
on
Hello,
I have a JS function that I need to get midnight value.

E,g  (-2 days) given today is 2/26/2014 . My function should return 2014-02-25T00:00:00.000Z
(-3 days) given today is 2/26/2014 . My function should return 2014-02-24T00:00:00.000Z

How can this be done with moment.js or javascript


Thanks for your help
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
How about this
<script type="text/javascript">
function getISODateString(days)
{
	var date = new Date();
	date.setUTCHours(0,0,0,0);
	date.setUTCDate(date.getDate() + days + 1);
	return date.toISOString();
}
alert(getISODateString(-3));
</script>

Open in new window

Author

Commented:
Thank you
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome - thanks for the points.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial