Solved

How to increment and decrement a date by 1+visual basic 6.0

Posted on 2011-02-21
6
2,768 Views
Last Modified: 2012-06-21
Hi,
Any suggestions on how to  increment and decrement a date by 1.

Cheers
0
Comment
Question by:RIAS
6 Comments
 
LVL 12

Assisted Solution

by:prashanthd
prashanthd earned 62 total points
ID: 34941839
Try this

Dim NextTime As Date = Now        ' Current date and time.
NextTime = NextTime.AddDays(3.4)  ' Increment by 3 2/5 days.
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 63 total points
ID: 34941845
Did you look at the dateAdd-function. You can add 1 day (interval = d, number = 1) or subtract one (interval = d, number = -1)

VBSCRIPT:http://www.w3schools.com/Vbscript/func_dateadd.asp
VB6: http://www.vb6.us/tutorials/understanding-vb6s-dateadd-function
0
 
LVL 9

Assisted Solution

by:s_chilkury
s_chilkury earned 62 total points
ID: 34941848
Use DateAdd function of VB 6.0

Check this:

http://www.vb6.us/tutorials/understanding-vb6s-dateadd-function
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 65

Accepted Solution

by:
RobSampson earned 63 total points
ID: 34941849
Hi, in VB6, you use DateAdd:

To get one day subtracted:
dteNewDate = DateAdd("d", -1, Now)

To get one day added:
dteNewDate = DateAdd("d", 1, Now)

Regards,

Rob.
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 34941852
You can also try this code
Dim Msg, Number, StartDate As String   'Declare variables.
Dim Months As Double
Dim SecondDate As Date
Dim IntervalType As DateInterval
IntervalType = DateInterval.day   ' Specifies months as interval.
StartDate = InputBox("Enter a date")
SecondDate = CDate(StartDate)
Number = InputBox("Enter number of days to add/subtract")
days = Val(Number)
Msg = "New date: " & DateAdd(IntervalType, days, SecondDate)
MsgBox(Msg)

Open in new window

0
 

Author Closing Comment

by:RIAS
ID: 34941871
Cheers!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now