{"id":40,"date":"2007-05-02T17:02:17","date_gmt":"2007-05-02T22:02:17","guid":{"rendered":"http:\/\/www.pixelwit.com\/blog\/2007\/05\/02\/flash-actionscript-date-suffix-code\/"},"modified":"2011-12-02T09:21:29","modified_gmt":"2011-12-02T14:21:29","slug":"flash-actionscript-date-suffix-code","status":"publish","type":"post","link":"https:\/\/www.pixelwit.com\/blog\/2007\/05\/02\/flash-actionscript-date-suffix-code\/","title":{"rendered":"Flash ActionScript Date Suffix Code"},"content":{"rendered":"<p>I&#8217;ve become fairly familiar with the Flash Date object and thought I&#8217;d share some handy code showing how to append the proper suffix to a date or any other number.  In case you don&#8217;t know what I&#8217;m talking about, a &#8220;number suffix&#8221; or &#8220;ordinal indicator&#8221; is the string of letters that follows a number to help make it more human readable.  For example the number suffix &#8220;nd&#8221; makes &#8220;May 2nd, 2007&#8221; a little easier to read than &#8220;May 2, 2007&#8221;.<\/p>\n<p>Here&#8217;s the code I wrote to handle all my numeric and date suffix needs:<!--more--><\/p>\n<div class=\"codecolorer-container actionscript default\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"actionscript codecolorer\"><span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw2\">function<\/span> getNumberSuffix<span class=\"br0\">&#40;<\/span>num<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span><span class=\"br0\">&#40;<\/span>num == <span class=\"nu0\">0<\/span><span class=\"br0\">&#41;<\/span><span class=\"kw1\">return<\/span> <span class=\"st0\">&quot;&quot;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw3\">Math<\/span>.<span class=\"kw3\">floor<\/span><span class=\"br0\">&#40;<\/span>num<span class=\"sy0\">\/<\/span><span class=\"nu0\">10<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">%<\/span>10===<span class=\"nu0\">1<\/span><span class=\"br0\">&#41;<\/span><span class=\"kw1\">return<\/span> <span class=\"st0\">&quot;th&quot;<\/span>;<br \/>\n&nbsp; &nbsp; num <span class=\"sy0\">%<\/span>= <span class=\"nu0\">10<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span><span class=\"br0\">&#40;<\/span>num<span class=\"sy0\">&gt;<\/span><span class=\"nu0\">3<\/span> <span class=\"sy0\">||<\/span> num===<span class=\"nu0\">0<\/span><span class=\"br0\">&#41;<\/span> <span class=\"kw1\">return<\/span> <span class=\"st0\">&quot;th&quot;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span><span class=\"br0\">&#40;<\/span>num===<span class=\"nu0\">1<\/span><span class=\"br0\">&#41;<\/span><span class=\"kw1\">return<\/span> <span class=\"st0\">&quot;st&quot;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span><span class=\"br0\">&#40;<\/span>num===<span class=\"nu0\">2<\/span><span class=\"br0\">&#41;<\/span><span class=\"kw1\">return<\/span> <span class=\"st0\">&quot;nd&quot;<\/span>;<br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"st0\">&quot;rd&quot;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><br \/>\n<span class=\"kw1\">for<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw2\">var<\/span> i=<span class=\"nu0\">0<\/span>; i<span class=\"sy0\">&gt;<\/span><span class=\"nu0\">120<\/span>; i++<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw3\">trace<\/span><span class=\"br0\">&#40;<\/span>i+getNumberSuffix<span class=\"br0\">&#40;<\/span>i<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span>;<br \/>\n<span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"co1\">\/\/<\/span><\/div><\/div>\n<p>And here are the trace results:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;width:100%;height:700px;\"><div class=\"text codecolorer\">0<br \/>\n1st<br \/>\n2nd<br \/>\n3rd<br \/>\n4th<br \/>\n5th<br \/>\n6th<br \/>\n7th<br \/>\n8th<br \/>\n9th<br \/>\n10th<br \/>\n11th<br \/>\n12th<br \/>\n13th<br \/>\n14th<br \/>\n15th<br \/>\n16th<br \/>\n17th<br \/>\n18th<br \/>\n19th<br \/>\n20th<br \/>\n21st<br \/>\n22nd<br \/>\n23rd<br \/>\n24th<br \/>\n25th<br \/>\n26th<br \/>\n27th<br \/>\n28th<br \/>\n29th<br \/>\n30th<br \/>\n31st<br \/>\n32nd<br \/>\n33rd<br \/>\n34th<br \/>\n35th<br \/>\n36th<br \/>\n37th<br \/>\n38th<br \/>\n39th<br \/>\n40th<br \/>\n41st<br \/>\n42nd<br \/>\n43rd<br \/>\n44th<br \/>\n45th<br \/>\n46th<br \/>\n47th<br \/>\n48th<br \/>\n49th<br \/>\n50th<br \/>\n51st<br \/>\n52nd<br \/>\n53rd<br \/>\n54th<br \/>\n55th<br \/>\n56th<br \/>\n57th<br \/>\n58th<br \/>\n59th<br \/>\n60th<br \/>\n61st<br \/>\n62nd<br \/>\n63rd<br \/>\n64th<br \/>\n65th<br \/>\n66th<br \/>\n67th<br \/>\n68th<br \/>\n69th<br \/>\n70th<br \/>\n71st<br \/>\n72nd<br \/>\n73rd<br \/>\n74th<br \/>\n75th<br \/>\n76th<br \/>\n77th<br \/>\n78th<br \/>\n79th<br \/>\n80th<br \/>\n81st<br \/>\n82nd<br \/>\n83rd<br \/>\n84th<br \/>\n85th<br \/>\n86th<br \/>\n87th<br \/>\n88th<br \/>\n89th<br \/>\n90th<br \/>\n91st<br \/>\n92nd<br \/>\n93rd<br \/>\n94th<br \/>\n95th<br \/>\n96th<br \/>\n97th<br \/>\n98th<br \/>\n99th<br \/>\n100th<br \/>\n101st<br \/>\n102nd<br \/>\n103rd<br \/>\n104th<br \/>\n105th<br \/>\n106th<br \/>\n107th<br \/>\n108th<br \/>\n109th<br \/>\n110th<br \/>\n111th<br \/>\n112th<br \/>\n113th<br \/>\n114th<br \/>\n115th<br \/>\n116th<br \/>\n117th<br \/>\n118th<br \/>\n119th<\/div><\/div>\n<p>Hope you find it helpful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ActionScript code used to determine the proper ordinal or numeral suffix (i,e, st, nd, rd, th) to append to any number.  For example 112 returns &#8220;th&#8221; while 122 returns &#8220;nd&#8221;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[8],"tags":[23,47],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-flash","tag-actionscript","tag-date"],"_links":{"self":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":0,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pixelwit.com\/blog\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}