Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

In my program, i was dealing with 2 DateTime which is the departure time and arrival time of customer at specific airport. These DateTime data will be provided by a travel agent through web service where as there will be only the following data provided:

(Departure Part)
- Date 1
- Time 1
- Country Code 1 (ISO 3166)
(Arrival Part)
- Date 2
- Time 2
- Country Code 2 (ISO 3166)

DateTime 2 have to convert to DateTime 1 where there is no TimeZone or TimeZoneID info provided. Is there any possible way to do this without manually storing all the country code and their corresponding TimeZoneID in database? Is there any function in TimeZoneInfo that can archive this? Or is there any way to retrieve the related timezone by just using the country code?

P.S: Sorry for my bad grammar.
Posted
Updated 18-Jan-11 23:32pm
v4
Comments
thatraja 19-Jan-11 10:06am    
Hi, please use the 'Add comment' link below the answers if you want to clarify the things about that, don't post a answer for that because it won't notify the answerers. Ok
BTW I have moved your message & notified them. please keep continue that way.

You could just store GMT, and let the client app adapt it to local time.
 
Share this answer
 
Comments
thatraja 19-Jan-11 10:04am    
[Comment from OP]
Hi John & OriginalGriff,

Yup, i will store the DateTime as GMT in the database. However, the problem is i'm not sure how to convert it into GMT as there are no TimeZone info provided at all. I have to retrieve the TimeZone by using just the country code.

I think TimeZoneInfo.FindSystemTimeZoneById is only usable if we know exactly what is the TimeZoneId, am i right?
Espen Harlinn 19-Jan-11 10:28am    
5+ it's a good answer - it's good practice to allways store date & datetime in UTC - not sure why I bother to vote though... it feels like an unappreciated effort :)
Try looking at TimeZoneInfo.FindSystemTimeZoneById: MSDN[^]
 
Share this answer
 
Comments
thatraja 19-Jan-11 10:05am    
[Comment from OP]
Hi John & OriginalGriff,

Yup, i will store the DateTime as GMT in the database. However, the problem is i'm not sure how to convert it into GMT as there are no TimeZone info provided at all. I have to retrieve the TimeZone by using just the country code.

I think TimeZoneInfo.FindSystemTimeZoneById is only usable if we know exactly what is the TimeZoneId, am i right?
OriginalGriff 19-Jan-11 14:23pm    
If you look at the example in the link I posted, it refers to:
TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
Which implies that the ID should be pretty simple to access via the country ID, no? :laugh:
Convert it something like this:

C#
DateTime fromDB = new DateTime(1,1,2011,12,0,0);
fromDB.Kind = DateTimeKind.Utc;
DateTime converted = fromDB.DateToLocalTime();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900