cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Date & Time Keyword Value from Unity Script

Seth_Yantiss
Star Collaborator
Star Collaborator

Hello,

Does anyone have some example code that posts a date & time value to a Date & Time keyword type.   When I have a string variable, I get an error...  So I am stuck at figuring out the element type, and from there the proper format of the variable.

Thanks for any assistance!

Seth

5 REPLIES 5

Daniel_Quill
Elite Collaborator
Elite Collaborator

Instead of passing a string variable you need to pass a DateTime object.

Take a look at http://msdn.microsoft.com/en-us/library/system.datetime.aspx for more information on creating DateTime objects.

Robert_Angus
Star Contributor
Star Contributor

Seth,

Here's the method I use to pass in a string and return a date. I'm sure someone else might have a better solution, but this one does work for us...

In this case, we're getting the date in the yyyyMMdd format. You can see more information about some of the settings on this function here: http://msdn.microsoft.com/en-us/library/ms131044

        public DateTime FixDate(string date) {            
            CultureInfo enUS = new CultureInfo("en-US");
            DateTime dt;
            DateTime.TryParseExact(date.Trim(), "yyyyMMdd", enUS, DateTimeStyles.None, out dt);
            
            return dt;
        }

John_Anderson4
Star Collaborator
Star Collaborator

If your date string is in a more standard format like mm/dd/yyyy, you could just use DateTime.Parse

http://msdn.microsoft.com/en-us/library/1k1skd40.aspx

DateTime convertedDate = DateTime.Parse(dateString);

All good stuff!   Thanks Guys!   With tidbits from each, I've been able to craft the unity keyword update:

Dim keyModifier As KeywordModifier = document.CreateKeywordModifier()

Dim PostDate as DateTime = DateTime.Now()

PostDate.Kind = DateTimeKind.Local

' Add update keyword call to keyword modifier object

keyModifier.AddKeyword(KEYWORD_TYPE,PostDate)

' Apply keyword change to the document

keyModifier.ApplyChanges()

output =String.Format("Keyword Type: '{0}' Value: '{1}' added to Document {2}.", KEYWORD_TYPE, PostDate, DOCUMENT_ID)

Aside to the Communities Admin...  I really dislike how this text window formats pasted text.  and every [Enter] is a full paragraph.

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.