Creation date

U

Ulf Nilsson

Hi,
If I want to see if a document has been created, I
use "ActiveDocument.BuiltInDocumentProperties("Creation
Date")".

How can I find out if a document has been created before
a certain date? "Creation date" includes a time-stamp
that makes things complicated for me.

Background:
If a document has been created before October 1, certain
things will happen if a button is pressed. I a document
has been created after October 1, some other things will
happen.

/ Ulf
 
J

Jay Freedman

Hi Ulf,

One way to handle this is with the DateDiff function. Here's a sample:

Private Function CheckCreateDate() As Integer
' returns -1 if active doc create date is
' between 1 Jan and 31 Sep inclusive
' returns 0 if create date is 1 Oct
' returns 1 if create date is between
' 2 Oct and 31 Dec inclusive
Dim CreateDate As Date
Dim TestDate As Date
Dim CreateYear As String
Dim DaysDiff As Long

CreateDate = CDate(ActiveDocument _
.BuiltInDocumentProperties(wdPropertyTimeCreated))

' build a date for 1 Oct in the
' same year as CreateDate
CreateYear = Year(CreateDate)
TestDate = CDate("1 October " & CreateYear)

' do the comparison
DaysDiff = DateDiff("d", TestDate, CreateDate)

If DaysDiff < 0 Then
CheckCreateDate = -1
ElseIf DaysDiff > 0 Then
CheckCreateDate = 1
Else
CheckCreateDate = 0
End If
End Function

Public Sub test()
Select Case CheckCreateDate
Case -1
MsgBox "Before 1 Oct"
Case 0
MsgBox "Exactly 1 Oct"
Case 1
MsgBox "After 1 Oct"
End Select
End Sub
 
U

Ulf Nilsson

Thanks Jay,
It worked fine. I just changed:
TestDate = CDate("1 October " & CreateYear)

to

TestDate = CDate("1 Oktober " & CreateYear)

The change was made because I use the Swedish version of
Office.

/ Ulf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top