Get Original Published Date

Topics: Customizing Orchard
May 8, 2013 at 6:47 PM
Not to sure how to get the original published date. I am using the Publish Later feature so CreatedUtc isn't an option. And, PublishedUtc gets updated if the content gets modified after it has been published, not sure if that is a bug or not, since there is a ModifiedUtc.
May 8, 2013 at 8:53 PM
What do you mean by original published date? The first time a content item was published?
May 8, 2013 at 9:13 PM
May 28, 2013 at 2:09 AM
You could look at the version records, and take the published date from the oldest one.
Jun 13, 2013 at 12:24 PM

I have this problem as well. How would one extract the published date from the oldest one?

Jun 13, 2013 at 1:41 PM
I might be on to something...
ContentItemVersionRecord cvr = Model.ContentPart.ContentItem.VersionRecord;
var ContentItemVersionRecord = cvr.ContentItemRecord.Versions.First();
I believe this might be the first Version Record, but i dont know how to extract the date. A nudge in the right direction would be greatly appreciated :)

Thanks in advance,
Jun 15, 2013 at 3:50 PM

@using Orchard.ContentManagement
@using Orchard.Core.Common.Models
    var id = Model.ContentPart.ContentItem.Id;
    IContentManager cm = Model.ContentPart.ContentItem.ContentManager;
    IEnumerable<ContentItem> contentItems = cm.GetAllVersions(id);
    ContentItem first = contentItems.First();
    var CreatedUtc = first.As<CommonPart>().CreatedUtc;  

<div class="published">
    <span class="day">@Display.DateTime(DateTimeUtc: CreatedUtc, CustomFormat: T("dd"))</span>
    <span class="month">@Model.ContentPart.PublishedUtc.ToString("MMM")</span>
I also got the right date with just this in the view:
<div class="published">
    <span class="day">@Display.DateTime(DateTimeUtc: Model.ContentPart.CreatedUtc, CustomFormat: T("dd"))</span>
    <span class="month">@Model.ContentPart.PublishedUtc.ToString("MMM")</span>
I am not sure if i have to get the date from the first version?

The default view looks like this:
<div class="published">
    @Display.PublishedState(createdDateTimeUtc: Model.ContentPart.CreatedUtc, publisheddateTimeUtc: Model.ContentPart.PublishedUtc)
Unfortunately, Display.PublishedState doesnt take CustomFormat as an argument, it does however call Display.DateTime from inside the function. Display.DateTime wants CreatedUtc as argument and you can also set your own CustomFormat :) AND thats why i used Display.DateTime instead.

Any thoughts (from someone more skilled in Orchard internals than myself) on this approach?

Jun 16, 2013 at 10:01 AM
You can create your own shape?
public class Shapes : IShapeTableProvider {
    public Shapes() {
        T = NullLocalizer.Instance;

    public Localizer T { get; set; }
    public IHtmlString PublishedState(dynamic Display, DateTime createdDateTimeUtc, DateTime? publisheddateTimeUtc, LocalizedString customFormat) {
        if (!publisheddateTimeUtc.HasValue) {
            return T("Draft");

        return Display.DateTime(DateTimeUtc: createdDateTimeUtc, CustomFormat: customFormat);
Jun 17, 2013 at 5:54 PM
Yeah, I suppose that's even better =)

I am still learning the ins and outs of Orchard. For now i try to stick to modifying existing views, and building simple modules.

Followup question:
Is it enough to pass Model.ContentPart.CreatedUtc as an argument, or is it better to get CreatedUtc from the first version (see my solution above)?

Jun 30, 2013 at 12:54 PM
Noone knows?
Jun 30, 2013 at 2:10 PM
You don't have to get the CreatedUtc value from the first version, as CommonPart.CreatedUtc already returns that value.
Jul 3, 2013 at 10:48 AM
Thank you.