For Zoho Services only:


I'm actually part of a bigger team at Ascent Business Solutions where we have support technicians and project consultants. Support is for smaller technical fixes but this can include developments, reports or integrations; depending on the size of the task. Projects are for more time-consuming developments such as revamps of the Zoho Suite of apps or on-site training. The advantage of a team is that if I am out-of-office for a day or so, there is always someone at Ascent Business Solutions who can deal with any queries/issues you may have.

Our support rates can be found and purchased at http://ascentbusiness.co.uk/zoho-support-2. A support bundle doesn't have an expiry date. So whether we can do what you want within the bundle and a year later need further support, if there are minutes left on the bundle then there is no additional charge.

Our project rates for bigger developments can be found at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices and will involve a dedicated project consultant along with developers who will hold your hand through the development process.

If you want help building a solution for one of the Zoho Apps in the Zoho Suite, contact us on 0121 293 8140 (UK) or by email at info@ascentbusiness.co.uk. You can also visit our website at http://ascentbusiness.co.uk.

I regularly build and specialize in 2-way API integrations for Xero, Shopify and eBay.

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 :: Article: 655

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: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used 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

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

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 - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.