Developer forum

Forum » Development » Assign Date/Time extentions

Assign Date/Time extentions


Reply
Hi,

Is there a way to quickly apply all the Date/Time extentions to a custom tag?

Nuno

Replies

 
Reply
Hi Nuno,

The SetTag method on a Template V2 that accepts a date has code like this:

public void SetTag(string Name, DateTime Value)
{
  if (Name.StartsWith("Global:") || this.HtmlHasPartialTag(Name))
  {
    this.SetTag(Name + "", Value.ToShortDateString());
    this.SetTag(Name + ".Day", DateAndTime.DatePart(DateInterval.Day, Value, FirstDayOfWeek.Sunday, FirstWeekOfYear.Jan1));
    this.SetTag(Name + ".Hour", DateAndTime.DatePart(DateInterval.Hour, Value, FirstDayOfWeek.Sunday, FirstWeekOfYear.Jan1));
    ....
  }
}

For some reason, your tag name has to start with Global....

Cheers,

Imar
 
Reply
BTW, turns out it doesn't have to start with Global. Apparently, the second condition evaluates to true....

Cheers,

Imar
 
Reply

Hi Imar,

That's what we came up with. It could be a good idea to have a special SetDateTimeTag that would do all of it automatically.
 

Thanks,
Nuno

 
Nicolai Høeg Pedersen
Reply
Template.SetTag has 6 overloads. One of them takes a value parameter as Date - that will automatically make the date time extensions.

Just make sure you pass the date as a Date object and not a string...
 
Reply
Hi Nicolai,

Perfect. Thanks a lot.

Nuno

 

You must be logged in to post in the forum