Results 1 to 3 of 3
  1. #1
    Iami is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default 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 );

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    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.

  3. #3
    Iami is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts