Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Sibtracting Dates - Possible ?

Status
Not open for further replies.

BAWC01

Technical User
Nov 23, 2005
79
CH
Is it possible for Word to Subtract two dates and leave an integer

If so could you post me an example Please

Phil
 
Gerry

Don't know about you but I always have a look in help first exhaust that avenue then post a question here.

Could see anything in help that could help me

Thanks

Phil
 
Hi Phil, hmmmm. I typed in "difference in dates"...in Help, and got Datedif, which
"Returns a Variant (Long) specifying the number of time intervals between two specified dates."

It also has an example.

Then I went to Microsoft.com and typed in "difference in dates" in the Search box. I got:

What do you want to do?
Calculate the number of days between two dates

Calculate the number of months between two dates

Calculate the number of years between two dates

As you did not state how are you are getting the dates in the first place - and i thought, well, gosh, maybe he is using Date Fields....I typed in "Date Fields" in.....Help.

There is a bunch of stuff there, as well.

With all due respect, you must get exhausted quickly.

Can you even get one date? Can you get two dates? Have you tried using a subtraction operators, as in date1 - date2? Try a few things, and if you still have problems post back with what you have actually tried.

Gerry
 
Sorry, hit the button toto soon.

What, exactly, have you tried? Please state where you get the dates in the first place. What exactly are you doing?

There are so many ways to do this, it is hard to know where to start. Help is a good place. I suggest you look again.

Since you do not state your purpose, or intention, or even the circumstances, here is an example that may help.
Code:
Sub calculateDate()
   Dim dteOne As Date
   Dim dteTwo As Date

dteOne = ActiveDocument.FormFields("Text1").Result
dteTwo = ActiveDocument.FormFields("text2").Result
MsgBox dteTwo - dteOne
End Sub

And since you ARE posting in duplicate locations, I guess it is OK to post code here. This uses Formfields (format set as Dates), and displays the difference (in integers) between the dates in the formfields.

Some more details would help. Some more Help would also help.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top