SQL PHP HTML ASP JavaScript articles and free scripts to download
JavaScript Date

setDate date function

By using setDate we can add date to any date object. This function can take numeric value 1 to 30 depending on the month and display the date accordingly. The code below will display 15th day of the current month.

var dt= new Date();
dt.setDate(15);
document.write(dt);

The output of this will be What happens when we add more that 30 or 31st day to the date function. This will take us to future date starting from 1st day of the current month.

var dt= new Date();
dt.setDate(35);
document.write(dt);

Next month 5th or 4th date will be displayed like this. Now let us add 365 to this function. We will get next year this month. Here is the code.

var dt= new Date();
dt.setDate(365);
document.write(dt);

The output is here What happens when we use –negative number with setDate function.

var dt= new Date();
dt.setDate(-20);
document.write(dt);

It will display 20 days backword from 1st of the present month.

Be the first to post comment on this article :


Google+

More on JavaScript Date & Time
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer