Convert From Local Time to UTC (Given the local TimeZone) - vb.net

I've dates in different time zones.
How to convert them to UTC giving the respective time zone.
Something like this:
Dim Dated as DateTime = TempDate.ConvertToUniversalTime(TimeZone)

The DateTime object in .net provides the DateTime.ToUniversalTime method. Since you are using the VB Date type the DateTime.FromOADate and DateTime.ToOAdate will provide conversion between the Date and DateTime types (see Interop Considerations under Programming Tips here).
UPDATE: You might also want to check out Converting Times Between Time Zones.

Here's how to do it
Dim TimeZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time")
Dim Dated As DateTime = TimeZoneInfo.ConvertTimeToUtc(TempDate, TimeZone)
For the TimeZones IDs check:
TimeZone.GetSystemTimeZones

Related

BigQuery - Datetime vs Timestamp

I looked on the documentation for google big query data types, checking the differences between TimeStamp to Datetime data types.
As I understand the main difference is:
Unlike Timestamps, a DATETIME object does not refer to an absolute instance in time. Instead, it is the civil time, or the time that a user would see on a watch or calendar.
So when should I use Timestamp/Datetime?
Thanks
In most cases you will want to use the timestamp data type. It refers to an absolute point in time. BigQuery interprets any timezone information and represents the time internally as a UTC timestamp.
Very rarely would you use a datetime data type, which is a date and a time but no time zone. The example I like to give is that you'd use a datetime to represent pi day, 2017, since it occurs at 2017-03-14 15:09:26.535898 in each time zone separately.

Time difference issue in two different countries

There are two clients with same window application. One is in India and other one is in Belgium. Sql server and web service application is hosted at Belgium. In sql I am storing UTC date time.
Now issue is a time difference for this two clients. I want to show UTC time in history form that mean what is stored in Database I have to bind that data to gird. No any extra code because I suppose to bind UTC date-time. Event then I get time difference for this two client.
Blue header screen is of a Indian client and other one is of a Belgium client. In Belgium time is showing exactly as in Database but difference is for India. Am I missing anything in configuration or what?
You have to convert both time zone in standard UTC and save it. Used dateadd() function to manipulate datetime. such as
declare #IST_date datetime
declare #BE_date datetime
declare #UTC_date datetime
--Indian standard time is (GMT + 5:30 hrs)
-- Belgium standard time is ( GMT + 1 hour)
select #UTC_date = DATEADD(hh,5.30, #IST_date)
select #UTC_date = DATEADD(hh,1, #BE_date)
why not simply convert the value at display ?
DateTime MyDate = Data["ChangedDate"];
DateTime MyDateUTC = MyDate.ToUniversalTime();
tadaaaaa
Ditch System.DateTime and use Noda Time!
Getting Started with Noda Time
System.DateTime uses the system culture and time zone at unpredictable moments, where Noda Time works without any defaults. Takes a bit of work to understand, but you'll never look back.
Use Noda time on the client, and store all the values in UTC in the database. You may also wish to store the original time zone that the date time was entered in.

RestKit Date Parsing Uses Incorrect Timezone

If part of the data that RestKit gets from my server is a timestamp formatted as 2013-05-27 20:32:26 UTC, and later I want to find out the difference between the current time and this date, I do
NSTimeInterval difference = [[NSDate date] timeIntervalSinceDate:dateFromRestKit];
But this always seems to be off for me by 1 hour, and I'm guessing this is because I'm on BST, which is UTC+1. So I think that RestKit is ignoring the timezone specified in the date string, and is instead parsing the date using the current system timezone.
I understand that there may be some technical reason it ignores the time zone, but I found all this time stuff really difficult to get my ahead around so I'm not sure.
How can I work out the correct difference between the times?
Even if your timestamp contains the UTC format , try to specify the timezone for it again.
If you want the resulting difference of two date timezone in 'UTC' then , convert the other one in UTC format and then find the time Interval.
Do let me know , if any query. Or if possible , post your code , to get more clear about your question. (:

VB.NET - Find current timezone, then convert to Pacific

I tried searching around for the code, but I didn't have too much luck. I found little snippets and I know how to convert current time to UTC, but I just really want to know how to get the current time zone, then convert the time to pacific.
I have many users that use my software all the way from california to maine. So I need to find out what timezone they are in, then convert it to pacific no matter where they are so I can accurately compare the local time to my servers time.
You can use the TimeZoneInfo class to convert time zones for you:
Dim now As DateTime = DateTime.Now
MessageBox.Show(now.ToString())
Dim pacificNow = System.TimeZoneInfo.ConvertTime(now, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"))
MessageBox.Show(pacificNow.ToString())
You can read more about the TimeZones and the Ids on MSDN.

Which SQL datatype should I use to store datetime from GPS devices?

I'm working on a project where I have to gather data from GPS devices located in different countries (timezones + daylight savings) and display those data to different users also from different countries. I'm thinking about saving the date in UTC format (that is what I receive from the GPS device) but then again I belive I'll have trouble converting that date to the user's local date (I have to display historical data also so I'll have to account for daylight savings for the given date). Maybe the datetimeoffset datatype would be more appropriate but how would I go about converting the received UTC date to the datetimeoffset datatype? What would you suggest? Thanks!
As you don't have to store any time zone along with the datetime, you can store them as UTC. That has the advantage of being linear, and easy to document. You don't have to bother with gaps and overlaps at the daylight savings time switches.
Convert the date to the local time zone when you display it to the user. It doesn't make sense to convert it to a local time zone until you know which user will be viewing the data.