Change date format of custom iProperty

Change date format of custom iProperty

CadUser46
Collaborator Collaborator
1,212 Views
2 Replies
Message 1 of 3

Change date format of custom iProperty

CadUser46
Collaborator
Collaborator

I need to change the date format of an iProperty.  It gets created as dd/mm/yyyy and i want to change to dd-MMM-yy.

 

I was trying this but to no avail

oProp.Value = Format(oProp.Value,"dd-MMM-yy")

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Accepted solutions (1)
1,213 Views
2 Replies
Replies (2)
Message 2 of 3

CadUser46
Collaborator
Collaborator

Please note that the input is always a string in dd/mm/yyyy format but it may be interpreted by machines in any locale.


Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes
Message 3 of 3

CadUser46
Collaborator
Collaborator
Accepted solution

Couldn't wait any longer so here it is.

 

Sub Main()

    Dim invApp As Inventor.Application = ThisApplication
    Dim oDoc As Inventor.Document = invApp.ActiveDocument
    Dim oPropSet As PropertySet = oDoc.PropertySets("Inventor User Defined Properties")
    Dim oProp As Inventor.Property
    
    Try
    	oProp = oPropSet("MyProp")
    Catch
        oProp = oPropSet.Add(Now.ToString("dd-MMM-yy"), "MyProp")
    End Try

	Dim d As Date
	Try
		Dim arr() As String = Split(oProp.Value, "/", 3)
		d = DateSerial(arr(2), arr(1), arr(0))
		oProp.Value = Microsoft.VisualBasic.Strings.Format(d,"dd-MMM-yy")
	Catch
	End Try

End Sub

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

---------------------------------------------------------------------------------------------------------------------------
Inventor 2010 Certified Professional
Currently using 2023 Pro
0 Likes