You are viewing limited content. For full access, please sign in.

Question

Question

Adding Suffix To Date With Tokens

asked on December 19, 2018

My input value for a date is MM/DD/YYYY.  When I apply formatting is there any way to get the suffix for the day.  For example, if the value is 8/17/2018 and I want the result to be Friday August 17th is there anything I can use in apply formatting to get the "th" after 17.  Currently I am using dddd MMMM dd in apply formatting and that gives me Friday August 17

 

Thanks!

0 0

Replies

replied on December 19, 2018 Show version history

You'll have to use a script activity. The code isn't too difficult.

Here's a sample I pulled from our codebase, which I'm sure we ripped off from somebody else.

var dt = DateTime.Now;
var dateString = dt.ToString("dddd MMMM dd");

var ordinalSuffix = "th";
var lastDigits = dt.Day % 100;

if (lastDigits < 11 || lastDigits > 13)
{
	switch (lastDigits % 10)
	{
		case 1:
			ordinalSuffix = "st";
			break;
		case 2:
			ordinalSuffix = "nd";
			break;
		case 3:
			ordinalSuffix = "rd";
			break;
	}
}

var fullDateString = dateString + ordinalSuffix;

 

1 0
replied on December 19, 2018

I'm not aware of a way to do that with formatting. You could probably use a token calculator and some IF conditions to have it pick the appropriate one, then you could append your suffix token to the end of the date token, but I know that's not exactly an "easy" solution.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.