Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter S 169 posts 587 karma points
    Sep 18, 2014 @ 13:37
    Peter S
    0

    Can I change created date?

    We are moving a non-Umbraco site to a new Umbraco site and we'de like to update the created date to match the created date from the original cms. Is this possible? Otherwise our entire news archive will be more or less wrong.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 18, 2014 @ 13:59
    Jeavon Leopold
    101

    Hi Peter,

    You can do this by executing a SQL statement

    e.g.

    update umbracoNode SET createDate = GETDATE() where id = 128345
    

    Updating with your own date and nodeid

    Jeavon

  • Peter S 169 posts 587 karma points
    Sep 22, 2014 @ 10:00
    Peter S
    0

    Thank you, Jeavon!

  • Robert J. Bullock 386 posts 405 karma points
    Apr 07, 2015 @ 16:42
    Robert J. Bullock
    0

    It would be super useful if someone created a utility to do this from within Umbraco.

    Robert

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 07, 2015 @ 17:41
    Nicholas Westby
    0

    I usually just create a different date/time property. The creation date on the node itself should reflect the true creation time of the node. You could create another property called something like "Release Date" to reflect the date of publication. One could even use a content saved handler (see https://our.umbraco.org/documentation/Reference/Events-v6/ContentService-Events ) to auto-fill this property (but CMS users could still edit it).

  • David Podmore 16 posts 74 karma points
    May 29, 2015 @ 12:26
    David Podmore
    0

    Hi Nicholas,

    Fairly new to this...

    I was looking for something just like this - and got halfway there myself. I have a custom property "Date Override" on my News Article doctype.

    At the moment I create a variable in my view that uses that property if its available (and createDate if not). I'd love to use the service handler to update "Date Override" but it's a little beyond my knowledge at the moment and I really don't know what to do. Can you please help??

    Thanks, David.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    May 30, 2015 @ 08:33
    Nicholas Westby
    0

    David,

    Basically, you'll create a class that looks something like this:

    namespace ClassLibrary1
    {
        using System;
        using System.Linq;
        using Umbraco.Core;
        using Umbraco.Core.Events;
        using Umbraco.Core.Models;
        using Umbraco.Core.Services;
        public class Class1 : ApplicationEventHandler
        {
            protected override void ApplicationStarted(
                UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                ContentService.Saving += ContentService_Saving;
                base.ApplicationStarted(umbracoApplication, applicationContext);
            }
    
            void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
            {
                var nodes = e.SavedEntities
                    .Where(x => "NewsArticle".InvariantEquals(x.ContentType.Alias));
                foreach (var node in nodes)
                {
                    var date = node.GetValue<DateTime?>("dateOverride");
                    if (!date.HasValue)
                    {
                        node.SetValue("dateOverride", DateTime.Now);
                    }
                }
            }
        }
    }
    

    Most of that code comes from the link in my previous post. Note that I haven't tested it, but the basic ideas are:

    • Implement ApplicationEventHandler (gives you access to Umbraco events like ApplicationStarted).
    • Attach an event handler for when the content nodes are being saved.
    • If any of the content nodes are news articles that have a null value for their dateOverride property, default it to the current date.
  • Shada 55 posts 137 karma points
    Oct 07, 2015 @ 05:47
    Shada
    0

    I changed a createDate in the umbracoNode table. But when I try to get a date of creation, I can still get the old date.

    content.CreateDate.ToString()
    

    But when I look this content node through umbraco cms I see new created date.

    I tried to restart the server and delete umbraco.config, but it did not help.

  • Cory Colt 34 posts 130 karma points
    May 31, 2016 @ 16:38
    Cory Colt
    0

    Did you ever get an answer to this? I'm experiencing the same problem as this. I've updated the date in the db, but on the UI it's still showing the old date.

  • Thomas Myrvang 1 post 72 karma points
    Feb 22, 2018 @ 11:57
    Thomas Myrvang
    1

    Just in case someone is still wondering about this. After changing the date in the database, you need to republish the pages in the umbraco backend for the change to be visible.

Please Sign in or register to post replies

Write your reply to:

Draft