The previous post on working with custom iProperties shows how to create iProperties of various types, including dates. However, dates have one unique behavior, as shown below. There is a check box next to each date property, (circled in the picture below), that the user can check or uncheck to indicate if they want to set a date or not.
A date iProperty will always have a value, but there is one date that is considered the zero date. If you set the iProperty value to this date it will have the side-effect of removing the check from the box. The date is Jan. 1, 1601. The code below demonstrates creating two new custom iProperties. One will be set to the zero date and the other will be set to the current date.
Public Sub DateProperties()
Dim partDoc As PartDocument
Set partDoc = ThisApplication.ActiveDocument
' Get the custom property set.
Dim customPropSet As PropertySet
Set customPropSet = partDoc.PropertySets.Item( _
"Inventor User Defined Properties")
' Create the properties.
Dim dateValue As Date
dateValue = #1/1/1601#
Dim sample1 As Property
Set sample1 = customPropSet.Add(dateValue, "Zero Date")
dateValue = Now
Dim sample2 As Property
Set sample2 = customPropSet.Add(dateValue, "Now Date")
Here’s the result after running the program. Notice that the check box for the zero date property is unchecked.
This is also important to understand if you ever need to read the value of a date property. In the example above, the date for the Zero Date iProperty will be Jan. 1, 1601, but you should handle this date as a special case and treat it as though the date hasn’t been set.