Solved

Dates 5 and 7 days from now

Posted on 2014-03-19
7
373 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

770 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