.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to add days in date using javascript

Posted By:      Posted Date: August 25, 2010    Points: 0   Category :ASP.Net

Hi following is the javascript code which i used for adding days to date

my date is 25/08/2010  and i want to add 8 days to this date  the answer should be 03/09/2010. how it is possible. i tried following code but showing error.



<script type="text/javascript" language="javascript">

function check()
var myDate = new Date();
var vFormat="MM/dd/yyyy";
var vDay                = addZero(myDate.getDate()); 
var vMonth            = addZero(myDate.getMonth()+1); 
var vYearLong         = addZero(myDate.getFullYear()); 
var vYearShort        = addZero(myDate.getFullYear().toString().substring(3,4)); 
var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
var vHour             = addZero(myDate.getHours()); 
var vMinute           = addZero(myDate.getMinutes()); 
var vSecond           = addZero(myDate.getSeconds()); 
var myDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
myDateString           = myDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 

function addZero(vNumber){ 
    return ((vNumber < 10) ? "0" : "") + vNumber 


View Complete Post

More Related Resource Links

Javascript FromDate to Date Validation Help!

Hi,I want to check fromdate and todate in dd/mm/yyyy.The code below mentioned works perfect for single textbox(fromdate) ,but when tried to do for todate(textbox) it doesnot work properly.From Date Should not be greater than ToDate.Please Help.Below is the code:<html><head><title>Date Example</title><script type="text/javascript">    function isValidDate(sText) {        var reDate = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;        return reDate.test(sText);    }    function validate() {        var oInput1 = document.getElementById("txt1");        if (isValidDate(oInput1.value)) {            alert("Valid");        } else {            alert("Invalid!");        }    }</script></head><body>    <P>Date: <input type="

MOSS 2007 Calculate Due Date including working hours and working days

Hi, I've searched many forums for an answer to my problem but with very limited success. Basically, I've created a Sharepoint list where I would like to track a resolution of incidents versus SLA timings. I have a column with a receiving date, which is a date when the request was submitted and another column with priority code where I have 3 possible values: low (5 working days to close the request), medium (3 days) and high (1 day). What I would like to do is to automatically calculate due date for solving the incident based on the receiving date and the priority code. The thing is that now it is getting more complicated since I need to exclude saturdays and sundays from calculation, as well as national holidays. Then I would like to take into account working hours (from 8am to 4pm), for example if an incident with medium priority was submitted on Friday 5pm, then it would have its due date set to Wednesday 4pm (the request was sent after working hours so we have 3 full working days to complete it) Not sure if it is feasible to achieve using formulas, maybe some other way?

Validate (Javascript) if input date is within this range...


I'd like to validate if the inputed date is within this range:

3 weeks before today's date to 3 weeks after today's date 

The following Javascript code checks if the date is within either today's date or 2 weeks before:

var dateSystem = (dateToday.getMonth() + 1) + dtCh + dateToday.getDate() + dtCh + dateToday.getFullYear();
            var prev = new Date();
            //past date 14 dates before today
            prev.setDate(prev.getDate() - 14);
            var pastDate = (prev.getMonth() + 1) + dtCh + (prev.getDate()) + dtCh + prev.getFullYear();
            var time1 = new Date(dateSystem).getTime();
            dtStr = month + dtCh + day + dtCh + year;
            var dateuser = new Date(dtStr);
            var time2 = dateuser.getTime();
            if (time1 - time2 <= 1209600000 && time2 <= time1) {
                return true;
            } else {
                alert("Vaccines/Services date must be within this date range: " + pastDate + " to " + dateSystem);
                return false
            return true


I'm not sure how to modify. I actually got the code above from these forums.

Help is much appreciated!

Validate ASP.net calendar date selected with Javascript?


Is there any way I can use javascript to make sure the user has selected a date from my asp.net calendar? I have the calendar under an update panel:

                        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                <asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="Maroon"
                                    BorderWidth="1px" CssClass="calendar" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black"
                                    Height="200px" Width="305px" DayNameFormat="Shortest" ShowGridLines="False">
                                    <SelectedDayStyle BackColor="maroon" BorderColor="Black" BorderWidth="1px" Font-Bold="true" Font-Size="11pt" />
                                    <SelectorStyle BackColor="#FFCC66" />
                                    <TodayDayStyle Font-Bold="true" Font-Size="16pt"/>
                                    <OtherMonthDayStyle ForeColor="#CC9966" />

Getting records that 7 days pass today's date


I want to get all records that are 7 days pass today's date and not equal to today's date.  Don't know how to write it so I can get records 7 days old but with this procedure I'm still getting records that are due today.  Hope this makes sense.  Can someone assist me.

select * from libraryrequest
where  duedate > getdate() and duedate != getdate()

Javascript Date Range


How can I arrange the javascript to check if the date the user has typed in is within this range? -

2 weeks prior to today and 2 weeks after today

Here's what I have so far:

var prev = new Date();
            var next = new Date();
            //past date 21 day before today
            prev.setDate(prev.getDate() - 21);
            //next date 21 days after today
            next.setDate(next.getDate() + 21);
            var pastDate = (prev.getMonth() + 1) + dtCh + (prev.getDate()) + dtCh + prev.getFullYear();
            var nextDate = (next.getMonth() + 1) + dtCh + (next.getDate()) + dtCh + next.getFullYear();
            var time1 = new Date(dateSystem).getTime();
            dtStr = month + dtCh + day + dtCh + year;
            var dateuser = new Date(dtStr);
            var time2 = dateuser.getTime();
            if (time1 - time2 <= 1209600000 && time2 <= time1) {
                return true;
            } else {
                alert("Vaccines/Services date must be within this date range: " + " " + "\n" + "\n" + "                      " + pastDate + " to " + nextDate);
                return false
            return true


getting time and date from datetime field in javascript


Hello guys, I need to get hours from the difference between two datetime fields. I wrote the javascript which will get the date from datetime field.

But its not getting the correct time that entered on date time field. Its defaultly getting the current time on my system.

So do you guys have any idea. How to get time from date time fields. and how calculate hours between two datetime fields using javascript.

Add days to a date field

How do I make a second date field that has a date 90 days greater than the
date in the first date field?

How to calculate days from two date textbox?


have two text box on which I give two date input by using rapid application development datepicker textbox. I have another text box on which I wanna show the duration of those two text box date.
I want to calculate total days of those to date. Can anyone please provide me a solution?

How to remove weekend days from current row date and Previous row date ?


column0    Column1                     ResultColumn

1              Mon, 07/12/2002           0 days

2              fri, 11/12/2002              4 days

3              mon, 14/12/2002           1 days

Thanks & Regards, PSWASULE

javascript: how to get the "absolute" Date?


Hi all, i was wondering how do we get the current Date using javascript which does not depend on the user's clock. (in other words if the user changes his clock we will still be able to get the correct date).

is this even possible?

reportviewer date parameter and calendar.. not working and javascript errors??



Hi, I've got this ssrs 2005 report that works great passing a few
security related parameters from asp.net codebehind. However, there
are two date related parameters that won't be coming from my web form,
but rather from the report form itself. When I test the report's date
parameters from visual studio it work fine, but when I attempt the
same report from a reportviewer no matter what input I place on the
report's date fields or even if I select the date picker, the report
simply resets to default and reloads. And actually the date picker
from the reportviewer does not not even pop up.


Here's my aspx code:

<%@ Page Language="VB" AutoEventWireup="false"
Inherits="_ReportViewer" MasterPageFile="~/Main/MasterPage.master"
    CodeFile="~/Reports/CashSales.aspx.vb"  Title="Cash Sales" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms,
Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content1"

What is the default in the Three State Workflow for how many days after due date to send email remin

I am setting up Three-State Workflow on an Issue Tracking list in MOSS 2007. My company does not allow SP Designer. I would like to know what is the default setting in this workflow for how many days after task due date to send the email reminder. Also, is there a way to change this setting under site collection administration? I would like it to send the reminder every 2 days.

Javascript Date Validation



I have a few Date validations to perform. I have the following columns "BirthDate","College Review Date", "Project Review Date" created in the custom list. In the Column Date and Time format option, I had choosen "Date Only" format.

I want to do some javascript validations on the date created. For example, BirthDate must be less than or equal to System Date. If the users selects a day greater the System Date, I want to alert the user. The alert should be provided after the date selection has changed, and not on the "OK" button click.

How to achieve this using javascript?

Thank you

SharePoint Designer Workflow - how to compare the Items if it is modified date is older than 20 days


I have a workflow which will keep track of specific meta data selection for a Custom List, as soon as an item gets updated to a specific selection say it as Resolved, I am sending an email to an user.


But after this I will need to check for every item in the list that If an item gets resolved and older than 20 days, I will have to move this item to a different list. I can get the resolved item date, store it an variable, but from here I will need to check if the item is older than 20 days and if it is this needs to be moved.

My point is the work-flows will be fired only when an item gets changed or updated, how to keep track of every item in the list and automatically move the older items without any manual intervention.


Am I clear in my requirement, if not kindly let me know.

If you have knowledge, let others light their candles in it.

function to calculate number of business days in a month for a given date


hi ,

Is there any function to calculate number of business days in a month for a particular date.  my input would be just a single date



ASP.NET, HTML, JavaScript Snippet Support (VS 2010 and .NET 4.0 Series)

This post covers another useful improvement in VS 2010 - HTML/ASP.NET/JavaScript snippet support. Snippets allow you to be more productive within source view by allowing you to create chunks of code and markup that you can quickly apply and use in your application with a minimum of character typing.

Visual Studio has supported the concept of "snippets" for VB and C# in previous releases - but not for HTML, ASP.NET markup and JavaScript. With VS 2010 we now support snippets for these content types as well.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend