SaaS CMS has officially launched! Learn more now.

current date (formatted) as default value in a string property


Hi Guys,

is there a elegant way of getting the current date in a string property when creating a page with this property.

And no the field cannot be a regular DateTime field, because we are using DXC and all simple dates added here are converted to UTC by default so the day changes, and we want the simple date of publishing all over the world.  (lots of threads about this problem) works great in other situations but not when you just want to show the date all over the world.

So what would be a approach to get the date in a string field on creation. ( in a certain format).

        GroupName = TabNames.Content,
        Name = "Publication Date",
        Description = "Publication Date of this News Article",
        Order = 9)]
        public virtual string PublicationDate {get; set;}
Aug 05, 2018 14:31

Hi Vishal,

If you're looking to set a value to a field on creation of the page you can override the SetDefaultValues method as shown below.

public override void SetDefaultValues(ContentType contentType)
    PublicationDate = DateTime.Today.ToString("dd-MM-yyyy");

This is then called automatically just the once when the page is created.

Aug 06, 2018 10:04

Thanks Paul.. this was too easy and was thinking too complex.. 

Aug 06, 2018 20:34
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.