How do I Add 14 Days to a Given Date in MM-DD-YYYY

# Thread: How do I Add 14 Days to a Given Date in MM-DD-YYYY

1. Senior Member
Join Date
Dec 1969
Posts
102

## How do I Add 14 Days to a Given Date in MM-DD-YYYY

I have to Get the Time Span (in Days) between two dates given by the user in MM-DD-YYYY format. The dates cannot be greater than 14 days apart.<BR><BR>I have enclosed the code I am using now, but I get a 0 difference.<BR><BR>Is there a function or standard way to do this?<BR><BR>Code:<BR>Dim sDate, sYYYY, sMM, sDD, DBStartDate, DBEndDate<BR>sDate = Request.Form("StartDate")<BR>sYYYY = Mid(sDate,7,4)<BR>sMM = Mid(sDate,1,2)<BR>sDD = Mid(sDate,4,2)<BR>DBStartDate = sYYYY & sMM & sDD<BR>&#039;Response.Write("&#060;Font Color=White&#062;DBStartDate: " & DBStartDate & "<BR>&#060;/Font&#062;")<BR><BR>eDate = Request.Form("EndDate")<BR>eYYYY = Mid(eDate,7,4)<BR>eMM = Mid(eDate,1,2)<BR>eDD = Mid(eDate,4,2)<BR>DBEndDate = eYYYY & eMM & eDD<BR>&#039;Response.Write("&#060;Font Color=White&#062;DBEndDate: " & DBEndDate & "<BR>&#060;/Font&#062;")<BR><BR>&#039; Add 2 weeks to the Start Date <BR>Diff = DateDiff("d", DBStart, DBEnd)<BR>Response.Write "Difference= " & Diff & "<BR>"<BR>

2. Senior Member
Join Date
Dec 1969
Posts
1,843

DateDiff is used to see how much time has passed between two dates (Hence, Date Difference) <BR><BR>There&#039;s another function.. called Date*** used to add dates together. No go look in the docs and you get a gold star if you can figure it out.

3. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

.

4. Senior Member
Join Date
Dec 1969
Posts
1,843

## You're no fun. <eop>

.

5. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

## They still have to look it up <eop>

.

6. Senior Member
Join Date
Dec 1969
Posts
1,843

## One time on TekTips.com

I had to explain why there&#039;s no DateSubtract function. This guy just couldn&#039;t handle the fact that adding a negative number is the same thing as subtracting. It was actually hilarious. I&#039;ll look up the thread and post the URL.

7. Senior Member
Join Date
Dec 1969
Location
Indianapolis, IN
Posts
1,755

## That's classic :-) <eop>

.

8. Senior Member
Join Date
Dec 1969
Posts
102

## RE: What Format does the Date Have to be in?

It comes in as MM-DD-YYYY which is Char. <BR><BR>Does it need to be in YYYMMDD format for DateAdd()?

9. Senior Member
Join Date
Dec 1969
Posts
1,843

## Format is irrelevant

because that&#039;s just how the date is *displayed*. If this is coming from a text box or something then you probably have to convert it to a VBS Date. You use the CDate() function to do this.

10. Senior Member
Join Date
Dec 1969
Posts
102

## RE: CDate, DateAdd and DateDiff

I found the code in ASPFAQ&#039;s to do some testing.<BR><BR>I used CDate, DateAdd and DateDiff to come up with this:<BR><BR>dateA = DateSerial( 2002, 3, 5 )<BR>dateB = CDate("5/3/2002")<BR>dateC = Date() <BR>dateD = CDate( 32.0 )<BR>dateE = DateAdd("d", 14, dateC)<BR><BR>Diff = DateDiff("d", dateD, dateE)<BR><BR>I get a Difference of 37562. What is this Number? When I CDate() this, I get 11/20/02. <BR><BR>What am I missing?

#### Posting Permissions

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