![]() |
|
|
#1
|
|||
|
|||
|
I want to use Visual Basic to calculate the days between the two dates. For example, the issue day is 2001-3-5, the valuation day is 2002-1-31, then what's the days between these two days? I try to use the function "Datediff", but the answer is always negative. Thank you very much.
|
|
#2
|
||||
|
||||
|
You refer to Excel so I assume you mean VBA, vs. VB. In Excel there is no function "Datediff" although there is a "DATEDIF" (which to my knowledge can not return a negative value).
If you'd like to try again, I may be able to help. Sorry, I know it's a b**ch, but I think the upshot here is...amazingly enough, accuracy is a requisite aspect of using computers. <font size=-1>[ This Message was edited by: Gates Is Antichrist on 2002-02-07 10:38 ]</font> <font size=-1>[ This Message was edited by: Gates Is Antichrist on 2002-02-07 10:39 ]</font> |
|
#3
|
|||
|
|||
|
Have you tried reversing the arguments? Or just sticking a negative sign in front?
|
|
#4
|
|||
|
|||
|
Is it necessary to use VB?
In a cell, you can just subtract the dates, no questions asked. From Excel's VB help: "Syntax DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])" Later on: "If date1 refers to a later point in time than date2, the DateDiff function returns a negative number." To make them positive, the dates should be listed in the function in chronological order. |
|
#5
|
|||
|
|||
|
If you're truly referring to VB, like in a macro, then you just need to define your variables as a date type (i.e. ValDate as Date). VB will accept standard date formats into the date type like "01/01/2002". Then just subtract your variables to get the number of days between dates.
|
|
#6
|
||||
|
||||
|
Quote:
Thy master spake the truth, Young Luke. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|