Solved

Adding and Subtracting Dates

Posted on 2009-05-13
3
249 Views
Last Modified: 2012-05-06
Hi Experts.   I have a bit of code that I'm taking from and old classic ASP/ VB Script page and trying to implement in a VB.NET/ASP.NET web application and I'm getting this error.

Operator '-' is not defined for type 'Date' and type 'Integer'.

The error is pointing to the 'If' statement.

My Code ( In the attached snippet)  works perfectly in Classic ASP/VB Script but .NET doesn't like it.  

All I want to do is add and or subtract days from the date value returned from my database.

What do I need to do in order to make this code function in .NET?
If reader.HasRows Then
                While reader.Read()
                    If ((reader("EventStartDate") - 6) <= StartDate And StartDate <= (reader("EventEndDate") + 6)) _
                    Or ((reader("EventStartDate") - 6) <= EndDate And EndDate <= (reader("EventEndDate") + 6)) _
                    Or (StartDate <= (reader("EventStartDate") - 6) And EndDate >= (reader("EventStartDate") - 6)) Then
                        intQuantityOut += reader("QuantityOrdered")
                    End If
                End While
 
                Return intQuantityOut
 
            Else
                Return 0
            End If

Open in new window

0
Comment
Question by:cdemott33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 24375082
you need to use DateAdd() function...

DateAdd(interval,number,date)

Parameter Description
interval Required. The interval you want to add
Can take the following values:

yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Weekday
ww - Week of year
h - Hour
n - Minute
s - Second
 
number Required. The number of interval you want to add. Can either be positive, for dates in the future, or negative, for dates in the past

date Required. Variant or literal representing the date to which interval is added
0
 
LVL 10

Accepted Solution

by:
MaxOvrdrv2 earned 500 total points
ID: 24375163

If ( DateAdd("d",-6,CDate(reader("EventStartDate"))) <= StartDate And StartDate <= DateAdd("d",6,CDate(reader("EventEndDate"))) ) _

Open in new window

0
 

Author Closing Comment

by:cdemott33
ID: 31580997
Thank you VERY much.  Worked perfectly!
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

729 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