Link to home
Start Free TrialLog in
Avatar of Overthere
Overthere

asked on

Sorting Date/Time when Different Time Zones

I have an internet application written in classic asp that records flight information and I need to be able to print out the itinerary in date/time order properly.  If I have someone leaving from NY and flying to Australia, on the return flight, I need to see them in proper order.  I could have the user enter the timezone as necessary, but then I'm needing to know how to properly sort these.  I have a few instances where the first return flight has a later time (in that time zone) than the second flight in its current time zone.  This is not ordered properly and I need assistance in how to get them entered so that I can sort properly.

Hard to put it into words, so I'm hoping someone can help.
TIA
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One way to put this together might be using the airport code data as a dictionary object.  Your sample data looks like this:
507,"Heathrow","London","United Kingdom","LHR","EGLL",51.4775,-0.461389,83,0,"E"
26,"Kugaaruk","Pelly Bay","Canada","YBB","CYBB",68.534444,-89.808056,56,-6,"A"
3127,"Pokhara","Pokhara","Nepal","PKR","VNPK",28.200881,83.982056,2712,5.75,"N"

Open in new window

We want to key on the airport code and get back the time difference from UTC and DST. Since there are only 2 fields in the dictionary object, the key and item.  We need to make our item into an array.  You can read up on dictionary objects here http://www.w3schools.com/asp/asp_ref_dictionary.asp


Function getUTC(theDateTime,airportCode)
Dim d
Set d=Server.CreateObject("Scripting.Dictionary")
'the item is a text field using the pipe "|" as a field separator.  
'Left of pipe is hours away from UTC.
'Right of pipe is DST
d.Add "LHR","0|E"
d.Add "YBB","-6|A"
d.Add "PKR","5.75|N"

arrX=split(d.Item(airportCode),"|")
utc=arrX(0)
dst=arrX(1)

'convert to UTC
'since the time difference is given in fraction of an hour, I am going to use hours instead of minutes.
timeUTC=dateadd("h",utc,theDateTime) 
'adjust for DST
'I think you can figure this out on your own.   You will need to write your own code to determine the DST.  The info to create your formula is here http://openflights.org/help/time.html
'Your next line of code would be
'timeUTC=~your formula for adjusting for DST here~       
getUTC=timeUTC
end function

Open in new window

Avatar of Overthere
Overthere

ASKER

Will be giving that a try.  Thx!