For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.

Zoho Deluge - Get English Ordinal

What?
This is a very quick note with the code to determine the English ordinal of a date (eg. "st" of "1st"). So in a date, instead of "Tuesday, 6 November 2018", I could want "Tuesday 6th of November 2018".

Why?
Well there's a long a way to do it (but reliable). But being limited to the lines of code you can run (ref. "Maximum number of executable statements", anything that reduces the number of lines used would be an improvement. This is how I was doing it previously.
copyraw
// get the date (eg. 1, 2, 3, ... 29, 30, 31)
	This_Day_Date = My_Date_Field.toString("d");

	// determine English ordinal
	English_Ordinal = "th ";
	if(This_Day_Date == "1" || This_Day_Date == "21" || This_Day_Date == "31")
	{
		English_Ordinal = "st ";
	}
	if(This_Day_Date == "2" || This_Day_Date == "22")
	{
		English_Ordinal = "nd ";
	}
	if(This_Day_Date == "3" || This_Day_Date == "23")
	{
		English_Ordinal = "rd ";
	}

	// display
	info My_Date.toString("d") + English_Ordinal;
  1.  // get the date (eg. 1, 2, 3, ... 29, 30, 31) 
  2.      This_Day_Date = My_Date_Field.toString("d")
  3.   
  4.      // determine English ordinal 
  5.      English_Ordinal = "th "
  6.      if(This_Day_Date == "1" || This_Day_Date == "21" || This_Day_Date == "31") 
  7.      { 
  8.          English_Ordinal = "st "
  9.      } 
  10.      if(This_Day_Date == "2" || This_Day_Date == "22") 
  11.      { 
  12.          English_Ordinal = "nd "
  13.      } 
  14.      if(This_Day_Date == "3" || This_Day_Date == "23") 
  15.      { 
  16.          English_Ordinal = "rd "
  17.      } 
  18.   
  19.      // display 
  20.      info My_Date.toString("d") + English_Ordinal; 

How?
I'm exploring various methods, so here's a couple using the built-in functions of Zoho deluge.
Method #1:
Using a list/array, I'm going to check the date against the 3 exceptions to this rule (11th, 12th and 13th of each month):
copyraw
// get the date (eg. 1, 2, 3, ... 29, 30, 31)
	This_Day_Date = My_Date_Field.toString("d");

	// determine English Ordinal
	Ordinals = "th,st,nd,rd".toList();
	English_Ordinal = Ordinals.get(0);
	EO_Index = This_Day_Date.substring(This_Day_Date.length() - 1).toLong();
	if((EO_Index == 1 || EO_Index == 2 || EO_Index == 3) && (This_Day_Date != "11" && This_Day_Date != "12" && This_Day_Date != "13"))
	{
		English_Ordinal = Ordinals.get(EO_Index);
	}
  1.  // get the date (eg. 1, 2, 3, ... 29, 30, 31) 
  2.      This_Day_Date = My_Date_Field.toString("d")
  3.   
  4.      // determine English Ordinal 
  5.      Ordinals = "th,st,nd,rd".toList()
  6.      English_Ordinal = Ordinals.get(0)
  7.      EO_Index = This_Day_Date.substring(This_Day_Date.length() - 1).toLong()
  8.      if((EO_Index == 1 || EO_Index == 2 || EO_Index == 3) && (This_Day_Date != "11" && This_Day_Date != "12" && This_Day_Date != "13")) 
  9.      { 
  10.          English_Ordinal = Ordinals.get(EO_Index)
  11.      } 


Method #2:
Using a map, set default to "th", check if the date (string) is in the map, if so use mapped value:
copyraw
// determine English Ordinal
	English_Ordinal = "th";
	Ordinal_Map = {"1":"st","2":"nd","3":"rd","21":"st","22":"nd","23":"rd","31":"st"};
	if(Ordinal_Map.containkey(My_Date_Field.toString("d")))
	{
		English_Ordinal = Ordinal_Map.get(My_Date_Field.toString("d"));
	}
  1.  // determine English Ordinal 
  2.      English_Ordinal = "th"
  3.      Ordinal_Map = {"1":"st","2":"nd","3":"rd","21":"st","22":"nd","23":"rd","31":"st"}
  4.      if(Ordinal_Map.containkey(My_Date_Field.toString("d"))) 
  5.      { 
  6.          English_Ordinal = Ordinal_Map.get(My_Date_Field.toString("d"))
  7.      } 


Method #3:
Given the current date and using the last character of the date, we can do the following:
copyraw
v_EnglishOrdinal = "th ";
	v_ThisDayDateLastChar = zoho.currentdate.toString("d").right(1).toLong();
	v_EnglishOrdinal = if(v_ThisDayDateLastChar == 1 && zoho.currentdate.toString("dd")!=11,"st",v_EnglishOrdinal);
	v_EnglishOrdinal = if(v_ThisDayDateLastChar == 2 && zoho.currentdate.toString("dd")!=12,"nd",v_EnglishOrdinal);
	v_EnglishOrdinal = if(v_ThisDayDateLastChar == 3 && zoho.currentdate.toString("dd")!=13,"rd",v_EnglishOrdinal);
  1.  v_EnglishOrdinal = "th "
  2.      v_ThisDayDateLastChar = zoho.currentdate.toString("d").right(1).toLong()
  3.      v_EnglishOrdinal = if(v_ThisDayDateLastChar == 1 && zoho.currentdate.toString("dd")!=11,"st",v_EnglishOrdinal)
  4.      v_EnglishOrdinal = if(v_ThisDayDateLastChar == 2 && zoho.currentdate.toString("dd")!=12,"nd",v_EnglishOrdinal)
  5.      v_EnglishOrdinal = if(v_ThisDayDateLastChar == 3 && zoho.currentdate.toString("dd")!=13,"rd",v_EnglishOrdinal)


Method #4:
Combining method 2 & 3, we can reduce getting the ordinal to 2 lines plus the output:
copyraw
v_NextRenewalDate = '2018-11-06';
	v_ThisDayDate = v_NextRenewalDate.toString("dd").toLong();
	v_ThisDayDateLastChar = v_NextRenewalDate.toString("d").right(1).toLong();
	v_EnglishOrdinal = if(v_ThisDayDateLastChar<4 && (v_ThisDayDate < 4 || v_ThisDayDate > 20),"st,nd,rd".toList().get(v_ThisDayDateLastChar-1),"th");

	// full formal date
	v_ContractDateFormatted = v_NextRenewalDate.toString("EEEE, d") + v_EnglishOrdinal + " of " + v_NextRenewalDate.toString("MMMM, yyyy");
	info v_ContractDateFormatted;	
	// yields Tuesday, 6th of November, 2018
  1.  v_NextRenewalDate = '2018-11-06'
  2.      v_ThisDayDate = v_NextRenewalDate.toString("dd").toLong()
  3.      v_ThisDayDateLastChar = v_NextRenewalDate.toString("d").right(1).toLong()
  4.      v_EnglishOrdinal = if(v_ThisDayDateLastChar<4 && (v_ThisDayDate < 4 || v_ThisDayDate > 20),"st,nd,rd".toList().get(v_ThisDayDateLastChar-1),"th")
  5.   
  6.      // full formal date 
  7.      v_ContractDateFormatted = v_NextRenewalDate.toString("EEEE, d") + v_EnglishOrdinal + " of " + v_NextRenewalDate.toString("MMMM, yyyy")
  8.      info v_ContractDateFormatted; 
  9.      // yields Tuesday, 6th of November, 2018 


Method #5:
if a list contains:
copyraw
v_NextRenewalDate = '2018-11-06';
	v_EnglishOrdinal = if("123".contains(v_NextRenewalDate.toString("dd").right(1)) && !"11,12,13".contains(v_NextRenewalDate.toString("dd")),"0,st,nd,rd".get(v_NextRenewalDate.toString("dd").right(1)),"th");

	// full formal date
	v_ContractDateFormatted = v_NextRenewalDate.toString("EEEE, d") + v_EnglishOrdinal + " of " + v_NextRenewalDate.toString("MMMM, yyyy");
	info v_ContractDateFormatted;	
	// yields Tuesday, 6th of November, 2018
  1.  v_NextRenewalDate = '2018-11-06'
  2.      v_EnglishOrdinal = if("123".contains(v_NextRenewalDate.toString("dd").right(1)) && !"11,12,13".contains(v_NextRenewalDate.toString("dd")),"0,st,nd,rd".get(v_NextRenewalDate.toString("dd").right(1)),"th")
  3.   
  4.      // full formal date 
  5.      v_ContractDateFormatted = v_NextRenewalDate.toString("EEEE, d") + v_EnglishOrdinal + " of " + v_NextRenewalDate.toString("MMMM, yyyy")
  6.      info v_ContractDateFormatted; 
  7.      // yields Tuesday, 6th of November, 2018 


Method #6:
The previous methods are inconsistent as it depends on the date format of the system. Instead (update 2021), I now use the following:
copyraw
v_GivenDate = '2021-09-21';
	m_Ordinals = {1:"st",21:"st",31:"st",2:"nd",22:"nd",3:"rd",23:"rd"};
	v_Ordinal = ifnull(m_Ordinals.get(v_GivenDate.toString("d").toLong()),"th");
	info v_Ordinal;
	// yields st
  1.  v_GivenDate = '2021-09-21'
  2.      m_Ordinals = {1:"st",21:"st",31:"st",2:"nd",22:"nd",3:"rd",23:"rd"}
  3.      v_Ordinal = ifnull(m_Ordinals.get(v_GivenDate.toString("d").toLong()),"th")
  4.      info v_Ordinal; 
  5.      // yields st 
Category: Zoho Deluge :: Article: 224

Accreditation

Badge - Zoho Creator Certified Developer Associate
Badge - Zoho Deluge Certified Developer
Badge - Certified Zoho CRM Developer

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com