Actuarial Outpost Excel about the date difference
 Register Blogs Wiki FAQ Calendar Search Today's Posts Mark Forums Read
 FlashChat Actuarial Discussion Preliminary Exams CAS/SOA Exams Cyberchat Around the World Suggestions

Meet Caitlin Cunningham, Entry Level Senior Recruiter

#1
02-07-2002, 08:52 AM
 Jovial Guan Join Date: Jan 2002 Posts: 13

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
02-07-2002, 10:31 AM
 Gates Is Antichrist Member SOA AAA Join Date: Feb 2002 Location: Hell Favorite beer: Pacifico Posts: 156

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
02-07-2002, 10:51 AM
 General Kenobi (ret.) Member Join Date: Sep 2001 Location: More powerful than you can possibly imagine Posts: 1,031

Have you tried reversing the arguments? Or just sticking a negative sign in front?
#4
02-07-2002, 12:05 PM
 Dr T Non-Fan Member Join Date: Sep 2001 Location: Just outside of Nowhere Posts: 59,131

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
02-07-2002, 12:36 PM
 Anonymous Guest Posts: n/a

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
02-07-2002, 03:37 PM
 Gates Is Antichrist Member SOA AAA Join Date: Feb 2002 Location: Hell Favorite beer: Pacifico Posts: 156

Quote:
 On 2002-02-07 10:51, Obi-Wan Kenobi wrote: Have you tried reversing the arguments? Or just sticking a negative sign in front?
I stand corrected. F@\$#%ing computers and that carefulness and accuracy thing! :emb:

Thy master spake the truth, Young Luke.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off

All times are GMT -4. The time now is 04:11 PM.

 -- Default Style - Fluid Width ---- Default Style - Fixed Width ---- Old Default Style ---- Easy on the eyes ---- Smooth Darkness ---- Chestnut ---- Apple-ish Style ---- If Apples were blue ---- If Apples were green ---- If Apples were purple ---- Halloween 2007 ---- B&W ---- Halloween ---- AO Christmas Theme ---- Turkey Day Theme ---- AO 2007 beta ---- 4th Of July Contact Us - Actuarial Outpost - Archive - Privacy Statement - Top