Skip to main content
Participant
July 16, 2008
Answered

Advanced date formatting - help

  • July 16, 2008
  • 2 replies
  • 307 views
Hi All,

Has anyone seen a tag, or got an algorithm that will format date ranges?

I want to go from

12, 13, 20, 21 September, 6, 7, 8, 9, 10, 11, 12 October

to

12-13, 20-21 September, 6-12 October


David Heacock
    This topic has been closed for replies.
    Correct answer Laverda668
    Very cool :-)

    Not quite what I was looking for, but still very cool. I ended up just building a set of nested loops and arrays to do this. Not very elegant, but effective.

    2 replies

    Inspiring
    July 16, 2008
    Laverda668 wrote:
    > Has anyone seen a tag, or got an algorithm that will format date ranges?

    the latest icu4j has this (maybe overkill for your purposes):

    http://www.sustainablegis.com/blog/cfg11n/index.cfm?mode=entry&entry=102C955B-20ED-7DEE-2AA628417A036E9E

    i haven't had a chance to wrap any of this up in a cfc but this more or less
    does what you want:

    <cfscript>
    // create a date interval now-->4 weeks from now
    // DateInterval class wants epoch offsets as LONG hence the getTime() calls
    dI=createObject("java","com.ibm.icu.util.DateInterval").init(now().getTime(),dateAdd("ww",4,now()).getTime());
    // create an interval format 3 letter months, 4 digit years, non-padded dates
    diF=createObject("java","com.ibm.icu.text.DateIntervalFormat").getInstance("yMMMd");
    writeoutput("#dif.format(di)#");
    </cfscript>

    which produces:

    Jul 16 – Aug 13, 2008

    currently this only works for gregorian calendar.
    Laverda668AuthorCorrect answer
    Participant
    July 16, 2008
    Very cool :-)

    Not quite what I was looking for, but still very cool. I ended up just building a set of nested loops and arrays to do this. Not very elegant, but effective.
    Inspiring
    July 16, 2008
    you are formatting strings, not date ranges.
    and, no, i do not know of a tag or an algorithm to do it, but someone
    else may come up with a crafty regex... i would give it a go myself if
    it wasn't so darn late...

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/