troubleshooting Question

running date correctly

Avatar of XK8ER
XK8ERFlag for United States of America asked on
JavaScript
1 Comment1 Solution231 ViewsLast Modified:
hello there,
I am trying to get the months and days correctly here..
for example if its 7th of January, I need it to be 07-01-2011
and its its 20th of December, I need it to be 20-12-2011
how can I do that?
for some reason its not giving me a 0 when the date its on 07-11-2011 like it should
<script type="text/javascript">
	var curdate = new Date();
	var year = curdate.getFullYear();
	var month = curdate.getMonth() + 1;
	if (month.length == 1) { month = '0' + month; }
	var day = curdate.getDate();
	if (day.length == 1) { day = '0' + day; }
</script>


<script type="text/javascript">		
	document.location.href=('http://domain.com/stats/index.php?action=backtostat&from_timestamp='+day+'-'+month+'-'+year+'&until_timestamp='+day+'-'+month+'-'+year);
</script>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros