sort dateTime problem

Cubist at aol.com Cubist at aol.com
Fri Dec 16 21:13:13 CST 2005


sez Timothy Miller:
>jacque at hyperactivesw.com replied:
>>Timothy Miller wrote:
>>>I just did quite a bit of haphazard troubleshooting. I isolated the 
>>>problem. The short dates are all preceded by a spacebar character. 
>>>If I remove the spacebar characters, the sort works correctly. This 
>>>is easily reproduced. It doesn't seem to matter whether items, 
>>>lines or words are being sorted.
>
>>It's correct behavior, based on the way that Rev calculates variable 
>>types automatically. Dates are composed of numbers and a date 
>>delimiter (usually "/" in the US). When the sort command sees a list 
>>of dates that are well formatted, it sorts them as expected.
>>But if there is a leading space, the engine interprets it as an 
>>ascii string instead -- since there are not suppoed to be spaces in 
>>dates -- and you get an alpha-numeric sort.

>>You could fix your sort command this way:
>>
>>   sort lines of cd fld "shedule.2" datetime by word 1 of item 2 of each
>
>Good idea. I wouldn't have thought of that.
   In order to forestall future problems of this kind, might it not be 
appropriate to nuke all those leading spaces wherever they occur? Something in this 
neighborhood might do the trick:

  put cd fld "shedule.2" into Fred
  put "" into CleanData
  repeat for each line LL in Fred
    put (word 1 of (item 2 of LL)) into item 2 of LL
    put LL into line (1 + the number of lines in CleanData) of CleanData
  end repeat
  put CleanData into cd fld "shedule.2"

   And, of course, you prolly want to make sure that no dates every get 
entered with leading spaces -- assuming that's even possible in your stack.



More information about the use-livecode mailing list