Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

get date

hello there,
this code is working fine but for some reason when that date is between 1st and 9th of the month it wont give day 01 or day 05...
it just gives 1 or 5.. how can I make it so that it always returns two digits for the day and month?
<script type="text/javascript">

var curdate = new Date();
var year = curdate.getFullYear();
var month = curdate.getMonth() + 1;
var day = curdate.getDate();

</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Eyal
Eyal
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If works, use the same logic for month as well

Raj
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might want to take a look at this article: Can I have a date?

https://www.experts-exchange.com/A_484.html