Javascript function to catch the next date of a calendar

Asked

Viewed 1,173 times

1

I have several calendars registered in my database, each calendar has its particularity.

I have a screen that makes the inclusion of a file and through a dropdown I choose the calendar that the periodicity of this file will respect.

Ex.: Daily, Weekly, Monthly and etc..

The idea is when the user clicks on a textbox specific balloon appears warning the next available date for the file.

Ex. Today is the 28th.

Balloon: "The next date is day 29/04/2015" if the periodicity is daily.

Can help me build this function with Javascript?

I tried using the code below, but my main question is how it returns the next calendar date in the function

function ExibeDica(obj, msg, useBottom, maxWidth){
       try
         {
        window.status = msg;
        var msgDica = document.getElementById('msgDica');               

        if(msgDica)
        {
            msgDicaTexto.innerHTML = msg;
            msgDica.style.zIndex = 9999;
            msgDica.style.left = obj.getClientRects()[0].left + document.body.scrollLeft - 2;
            msgDica.style.display = 'block';
            if (maxWidth != null)
                if (msgDica.offsetWidth > maxWidth) msgDica.style.width = maxWidth;
            if (useBottom)
                msgDica.style.top = obj.getClientRects()[0].bottom + document.body.scrollTop;
            else
                msgDica.style.top = obj.getClientRects()[0].top + document.body.scrollTop - msgDica.offsetHeight - 4;
        }
    }
    catch(e) {} 
}

function OcultaDica(){
    try
    {
        window.status = ''; 

        var msgDica = document.getElementById('msgDica');

        if(msgDica)
        {
            msgDica.style.display = 'none';
            msgDica.style.width = null;
        }
    } 
    catch(e) {}
}
  • What you’ve already done?

  • I tried to use a code from a tip I already had on the project.. my doubt is really how to bring this date to function, I will put the code I tried to use above

  • Do you already have any code done (any attempt) regarding the problem (calculating the date)? The code placed in the question does not affect anything in the solution of the problem.

1 answer

3

Check the methods of the Date objects, with them you can, take the current date, add days and/or months and use the new date.
I think in your case, just take the current date and add one day, you can do it like this:

// data atual (28)   
d = new Date();  

// acrescenta um dia (29)  
d.setDate(d.getDate() + 1);

// exibe o "novo" dia (29)  
d.getDate();

You can apply the same to the other rules.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.