Solved

I need help with Date arithmetic in VB6

Posted on 2014-01-09
3
346 Views
Last Modified: 2014-01-09
Hello Experts,
I need help with Date arithmetic in VB6.  I have a variable, which I will set to today's date.  Then I want to perform some Date arithmetic against that value.
For example:

Dim dteToday as Date
dteToday = '1/9/2014'

If I want the following result to be '1/11/2014', would I simply do this?
dteToday = dteToday +2

Of If I want the following result to be '1/6/2014', would I simply do this?
dteToday = dteToday - 3

Please let me know how to do this.  Thanks in advance.
mrotor
0
Comment
Question by:mainrotor
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 450 total points
ID: 39768264
yes, you can do that.
another way would be:

dteToday = dateadd("d", 2, dteToday)
respectively:
dteToday = dateadd("d", -3, dteToday)

http://msdn.microsoft.com/en-us/library/aa262710%28v=vs.60%29.aspx
0
 
LVL 25

Assisted Solution

by:Luis Pérez
Luis Pérez earned 50 total points
ID: 39768285
As long as you want to add or subtract days, there's no problem. You can do only by adding or subtracting a number. If you want to operate with another time unit (weeks, months...) you should use the DateAdd function.

Hope that helps.
0
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 39768290
Oops... late.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Close form "before" open 3 40
Run a batch file when a Crystal Report is opened 5 27
VB.NET (2008) - Refactoring Question 2 21
SQL LINE CONTINUATION ISSUE 12 33
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
A short article about problems I had with the new location API and permissions in Marshmallow
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

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