[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2759
  • Last Modified:

Moment.js - get start of day yesterday

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
0
SiemensSEN
Asked:
SiemensSEN
  • 2
1 Solution
 
Julian HansenCommented:
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

0
 
SiemensSENAuthor Commented:
Thank you
0
 
Julian HansenCommented:
You are welcome - thanks for the points.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now