Sam
Sam

Reputation: 461

How to programmatically set the date and time of the Publish field of Publishing section in Sitecore

XmlNode jobPostDate = xmlDocumentObject.SelectSingleNode("MsgData/HRS_JO_PST_OPN_DT)
var jPdate = jobPostDate.InnerText;
DateTime dt1 = Convert.ToDateTime(jPdate);
var HRS_JO_PST_OPN_DT = dt1;
newItem.Fields[Sitecore.FieldIDs.PublishDate].Value = HRS_JO_PST_OPN_DT.ToString();

I am using the above code to get the date (01/09/2013) and set it to the Publish field, but I am getting '1/1/0001' values, shown in below picture, in the field.

Publishing section with Publish and Unpublish set to '1/1/0001'

Please advise what I am doing wrong.

Upvotes: 1

Views: 1231

Answers (1)

Martijn van der Put
Martijn van der Put

Reputation: 4092

try this to set the value of the date field:

newItem.Publishing.PublishDate = dt1;

Use the Publishing.UnPublishDate property to set the unpublish date

Upvotes: 5

Related Questions