Results 1 to 5 of 5

Thread: sort a non US date format field

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    3

    Question sort a non US date format field

    Hi
    Would appreciate any assistance with this situation. Have successfully got a table of data appearing and sorting - except that we are in the UK and we have a different date format - dd mm yyyy. The Spry javascript assumes the dates are US format - mm dd yyyy and therefore when we sort them it doesn't sort correctly. I am hoping that we have simply missed a setting - otherwise do we have to dive into javascript?!

  2. #2
    Senior Member Power Poster
    Join Date
    Dec 2007
    Posts
    359

    Default

    Hello, John!

    We are a hosting company, and I would hazard a guess that you're inquiring about the Spry framework for AJAX from Adobe.

    Here's a link to the Spry AJAX Framework Documentation - it should be the best place to look for more information (if you are, indeed, seeking assistance with Adobe's product).

    ... and here's a bit of Javascript code which will swap your dates around:

    Code:
    <script type="text/javascript">
    var internationalDate = 'DDMMYYYY';
    var usDate = internationalDate.substring(2,4) + '/' + internationalDate.substring(0,2) + '/' + internationalDate.substring(4,8);
    alert(usDate); // Display the result of the script
    </script>
    Note: If you need to concatenate the date without any / characters, use the toString() method to ensure that the date's components are not added when the + operator is used.

    Example:

    Code:
    var internationalDate = '31032008';
    var usDate = internationalDate.substring(2,4).toString() + internationalDate.substring(0,2).toString() + internationalDate.substring(4,8).toString();
    alert(usDate); // Display the result of the script

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    3

    Default Thank you kindly - a bit more help may get us there

    I may need to be more specific - what you have suggested is good - so here goes. Imagine we have a table with lots of columns imported from an XML dataset, one of which is a date. In the US the date is formatted mmddyyy and Spry successfully sorts the date column beautifully - now imagine that the date is formatted ddmmyyyy - how can we inform Spry that the date format is non-US so that the sorting does not hiccup!

    Thanks
    John

  4. #4
    Senior Member Power Poster
    Join Date
    Dec 2007
    Posts
    359

    Default

    Aside from a very unreliable method (comparing the first two digits to determine whether they represent a number greater than 12 and then treating the date as though it were international), you will need to use some other item of data to denote whether the field's date is in US or international format.

    My recommendation would be to convert the date into a timestamp or ISO-formatted date before it is touched by any Javascript - doing so will ensure a standard date format wherever the data is used at the small price of regularly converting the date for display.

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    3

    Default

    Thank you Dan
    Will give this a go!

    John

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •