Solved

Adding and Subtracting Dates

Posted on 2009-05-13
3
248 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Finding the IIS version 5 37
VS 2015 is giving [No relevant source lines] 2 39
Query in AngularJS 8 46
Multi-Column Repeater 3 26
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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