Solved

Sorting Date/Time when Different Time Zones

Posted on 2013-06-28
3
571 Views
Last Modified: 2013-07-17
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
0
Comment
Question by:Overthere
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
Comment Utility
I assume you understand how to sort date/time but now you just need to account for time zones and daylight savings time.  

For any given airport you will want to first normalize for daylights savings time.  Then you want to normalize your data by adjusting to UTC.  This will put all time zones at the same time zone and adjust for local DST.

You need to start with a database of airport codes matched with hours from UTC http://openflights.org/data.html.

You will key on airport codes in order to match the starting time zone with airport ABC and the time zone db with airport ABC so you can find if it is in DST and the adjustment forward and backward for UTC.  

Use the adjusted time only for purposes of sorting.

About UTC
http://www.worldtimeserver.com/current_time_in_UTC.aspx
http://www.nhc.noaa.gov/aboututc.shtml
http://en.wikipedia.org/wiki/Coordinated_Universal_Time

About DST
http://www.timeanddate.com/time/dst/
https://en.wikipedia.org/wiki/Daylight_saving_time

Note some of your time conversions for UTC are in minutes and not hours.

To adjust your time in asp


http://www.w3schools.com/vbscript/func_dateadd.asp
dateadd("n",-180,startdate)

The "n" is for minutes

The -180 represents the number of minutes from UTC. In this sample, using -3hrs converts to 180 minutes.

The startdate would be the date of departure or arrival from the airport.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
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

0
 

Author Closing Comment

by:Overthere
Comment Utility
Will be giving that a try.  Thx!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now