Results 1 to 3 of 3
Thread: Just don't get it
- 12-13-2008, 09:49 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 2
- Rep Power
- 0
Just don't get it
Greeetings, new-be, don't understand what I need to do here
I am using the script below to input a Date stamp on a html form
I need to add 1 month to the date so that today's date will show 30 days in the future. I add 2 to the month date ie :2008-12-15 and it outputs
2008-13-15, I need to output 2009-01-15. Now I am not a 'guru' and just don't know enough knowledge to 'develop the fix'. I would appreciaiate any help I could get.
\<script type="text/javascript">
//set date var
d = new Date();
//set time vars
var second = d.getSeconds();
var minute = d.getMinutes();
var hour = d.getHours();
var weekDay = d.getDay();
var day = d.getDate() ;
var year = d.getFullYear();
var month = d.getMonth()+2;
//if minute less than 10 add leading zero
if(day<10) {
day = "0" + day;
}
if(month<10) {
month = "0" + month;
}
//make date string
var date = year+ "-" + month + "-" + day ;
//Create Function: set field value
function setFieldValue(id, value) {
document.getElementById(id).value = value;
}
window.onload = function() {
setFieldValue("DateExp", date );
}
</script>
- 12-13-2008, 10:06 PM #2
It is simple,if your result of the month is bigger than 12 and less than 24 then add 1 to your year,the same with the day,if your result of the day is bigger than 30 then add 1 to the month.I think you understood the concept .By the way it is not a JavaScript Forum ,it is Java Forum,Javascript is not Java.
- 12-17-2008, 06:30 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 2
- Rep Power
- 0
Just Don't Get it
Thanks for your response, I will ask in java scripts next time.
Your fix worked as long as I put the numbers in the script manualy,
My intent was to to have the system autonmatically create a date 30 days in the future each and every month without intervention. The fix you s8upplied will have to be modified agian and again. But it stirs me on the right track, thanks again.


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks