Hello Anthony,

I'm assuming that your times do not have dates associated so you don't need
to handle cross-midnight issues. I recommend saving a copy of your data
before you update fields, especially original ones.

I would suggest the best way of handling this is to add a new integer column
for each time field in your table. This field will be populated with a
seconds value. After adding a new integer field (called timesecs1 and
timesec2 in my example below), use Table > Update column on this field with
the following expression:

val(left$(time1, 2))*3600 + val(mid$(time1,4,2))*60 + val(right$(time1, 2))

This extracts the individual hours/minutes/seconds components and multiplies
them up to uniform seconds.

Repeat this for your second field, time2.

If you then want to add a third integer field with the time difference,
update this column with:

abs(timesecs2 - timesecs1)

The abs() function converts to positive so that the difference is
irrespective of which is greater between time1 and time2. If you want know
the real difference, even negative, loose the abs().

You can reformat your HH:MM:SS fields using a similar query to above. The
left$(), mid$(), and right$() functions allow you to extract parts of a
string, then use "+" in an expression to tie them together again. So, to
change to HHMMSS, update with:

left$(time1, 2) + mid$(time1,4,2) + right$(time1, 2)

Note that if you change the format first, the "convert to seconds"
expression above needs to be changed.

Hope that helps.

Regards,
Warren Vick
Europa Technologies Ltd.
http://www.europa-tech.com

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Anthony
Harrington
Sent: Friday, January 10, 2003 8:51 PM
To: [EMAIL PROTECTED]
Subject: MI-L Calculating Time Differences


Hello,

I have a mapinfo table which contains a string column representing time
values in the format

of HH:MM:SS. Is anyone aware of some sample code to perform an operation
like time1 - time2

(where the format is HH:MM:SS) ?

Alternatively can anyone tell me is there any way to tokenize/parse a string
in MapBasic

so as to remove the Hour or Minute values from a string formatted as above ?

Any information would be gratefully received.

Regards,

Anthony Harrington

--
+---------------------------------------------------------------------+
   _/_/_/_/_/  _/_/_/  __/_/_/_/  Anthony Harrington
      _/     _/    _/  _/     _/  Research Assistant
     _/     _/        _/     _/   Trinity College Dublin
    _/     _/        _/     _/    tel : +353 (0)1 608 2666
   _/     _/    _/  _/     _/     email: [EMAIL PROTECTED]
  _/      _/_/_/  __/_/_/_/       http://www.cs.tcd.ie/Anthony.Harrington
+---------------------------------------------------------------------+





---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 4857

Reply via email to