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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATEADD Syntax 1

Status
Not open for further replies.

MrKABC

Technical User
Jul 20, 2001
54
US
Hello all:

Another issue arose with my Date/Time syntax question located HERE:


It's a different question so I started a new thread.

This is a (hopefully) simple question about syntax of the "DateAdd" VBA command in MS Word 2003. I'm using the following code to populate a VBA text box:

Code:
Dim MountainTime as Date
...
MountainTime = DateAdd("h", -1, FormatDateTime(Now(), 3))

For the most part it works, returning a value in the text box of (for example) 10:29:22 PM.

However, sometimes I get an undesired value like this: 12/29/1899 10:29:22 PM

Where did the date come from? I specifically formatted for TIME only. Is my syntax wrong? Any ideas?
 
hi MrKABC,
I specifically formatted for TIME only
Not really, you only formatted the current time that way, which isn't the same as formatting the result of the calculation.

You might have more success with:
Code:
MountainTime = FormatDateTime(DateAdd("h", -1, Now()), 3)

Cheers

[MS MVP - Word]
 

MrKABC,

You need to understand Date/Time - Why do Dates and Times seem to be so much trouble? faq68-5827

AddDate returns a Date/Time value

FormatDateTime returns a STRING that is NOT a Date/Time value.

When I run your AddDate, I get [tt]6:16:39 AM[/tt] which has a VALUE of [tt]0.2615625.

Do you remenber I asked you what CDbl (conver to double) resulted in? You got an ERROR 'cuz you had TEXT and NOT a Date/Time value.

Read the FAQ and understand it! Then you ought to be able to figgure out this puzzel.



Skip,

[glasses] [red]Be Advised![/red] The only distinction between a bird with one wing and a bird with two, is merely...
a difference of A Pinion! [tongue]
 
Thank you Macropod, your advice was a life saver. A star for you! (smile)

Skip, thank you for your invaluable advice! I have bookmarked the FAQ and will most definitely give it a thorough going over.

I appreciate your advice! Thank you again!

A.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top