Solved

Dates 5 and 7 days from now

Posted on 2014-03-19
7
376 Views
Last Modified: 2014-03-19
I'm trying to get the dates, 5 and 7 days from now.
Example: Today = 3/19/2013, 5 days = 3/24/2013, 7 days = 3/26/2013

I do not want to count weekends, ie only count business days Mon-Fri.
Example: Today = 3/19/2013, 5 days = 3/26/2013, 7 days = 3/28/2013

Working in classic asp
<% 
Dim strToday, strFive, strSeven
strToday = Date()
strFive = Date() + 5
strSeven = Date() + 7
%>

Today: <%=strToday %><br />
5 Days: <%=strFive %><br />
7 Days: <%=strSeven %>

Open in new window

0
Comment
Question by:swaggerking
  • 4
  • 3
7 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 39940144
use the DateAdd function:

<% 
Dim strToday, strFive, strSeven
strToday = now
strFive = DateAdd( "d", 5, strToday )
strSeven = DateAdd( "d", 7, strToday )
%>

Today: <%=strToday %><br />
5 Days: <%=strFive %><br />
7 Days: <%=strSeven %>

Open in new window

0
 

Author Comment

by:swaggerking
ID: 39940171
Big Monty,
This still counts weekends. I only want it to count business days.
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 450 total points
ID: 39940325
read too fast, my apologies :)

try this:

<%
dim strToday, businessDays5, businessDays7
strToday = now()

select case WeekDay( strToday )
    case 2, 3, 4     '-- Monday - Wednesday
           businessDays5 = 7
           businessDays7 = 9
    case 5, 6    '-- Thursday - Friday
           businessDays5 = 7
           businessDays7 = 11
end select

strFive = DateAdd( "d", businessDays5, strToday )
strSeven = DateAdd( "d", businessDays7, strToday )
%>

Today: <%=strToday %><br />
5 Days: <%=strFive %><br />
7 Days: <%=strSeven %>

Open in new window


untested, but I think it'll work
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:swaggerking
ID: 39940409
No problem, I do it all the time.  This works, but only if the date (strToday) doesn't land on a weekend.

ie. if strToday = 3/22/2013 (weekend) then strFive and strSeven = 3/22/2013 as well.
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 450 total points
ID: 39940425
you'll need to add case conditions for both saturday and sunday, so change my case statement to:

select case WeekDay( strToday )
    case 1     '-- Sunday
           businessDays5 = 5
           businessDays7 = 9
    case 2, 3, 4     '-- Monday - Wednesday
           businessDays5 = 7
           businessDays7 = 9
    case 5, 6    '-- Thursday - Friday
           businessDays5 = 7
           businessDays7 = 11
    case 7     '-- Saturday
           businessDays5 = 6
           businessDays7 = 10
end select

Open in new window

0
 

Author Comment

by:swaggerking
ID: 39940447
Thanks. I appreciate your help.
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 39940458
my pleasure! happy coding :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question