Store GMT dates on a US server - asp.net

I'm from the UK, and have recently deployed a website on WinHost's Basic Package.
When using DateTime.Now() in C#, or GETDATE() in SQL, these are both returning something like GMT-8 (because the server is hosted in the US).
I think I'm a bit limited in terms of permissions on the server (for example I can't change my SQL Login Language).
What is the best method of storing these dates in GMT?

use DateTime.UtcNow and store as it is database.
When reading from database assume UTC and convert into UK time using TimeZoneInfo class.
Note that the SQL should not contain any information about time zone offsets.

In SqlServer use getUtcDate() to store all your datetime values. You can convert it to required timezone in your .NET application.

Description
I think you should store your DateTimes in UTC. Then you can simple convert it to another Timezone with the TimezoneInfo class.
Save DateTime.UtcNow to your database or use getUtcDate inside sql
Let the user choose his timezone and save them to to your database
Convert the UTC Time you have saved to the users timezone using TimeZoneInfo.ConvertTimeFromUtc
Sample
TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById(/* destination timezone (users timezone) */);
DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(YourDateTimeFromDatabase, cstZone);
More Information
How to do timezones? In asp.net mvc
MSDN - TimeZoneInfo Class

Related

Dynamics CRM 365 on premise unified interface webresource reading date field from form getting date in UTC

We have an on premise tenant and using unified interface.
I have a form which has a date field and its behaviour is set as User Local.
Date Field Setting On the same form I have a web resource that displays the same date field data on form load. I am using parent.Xrm.Page.getAttribute("fieldname").getValue() to get the date field value on web resource.
I know the date is getting stored in UTC format. It displays fine on the form but on the web resource it is one day behind.
Is it the timing issue that form has got the date in UTC format but before it converts it to local format, web resource reads it.
Please advise.
I have found the issue. If the time zone in CRM personal setting is different than the time zone setting of the machine then this problem happens. In my case CRM personal setting had Sydney as the time zone but machine was set for Brisbane time zone. –I

What's firebase / firestore timezone

Q1. May I know what's the timezone that firebase server and web console is?
Q2. Using FieldValue.serverTimestamp() to save data, how could I convert the timestamp to user timezone?
Q3. Could I configure timezone for firebase server?
Q4. While refer to firebase web console usage info, what's the timezone it showing?
What is the latency for latest usage to appear on web console usage section?
The timezone of Firestore Timestamp is in UTC, if you want to convert that timezone to the timezone your client has do this.
You can set the timezone with DateFormat() and parse the timestamps result with that timezone.
Date date = new Date(timestamp);
DateFormat utcFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Log.d("Date:",""+utcFormat.format(date));
Regarding Q3, I think since it's from a server-side perspective, you can't change it.
About Q4, I don't really know the latency.
Edit: I have found some info about Q3
https://firebase.google.com/docs/functions/schedule-functions
If you are doing Functions, you can setup the timezone.

Which date and time will insert into SQL Server Database if I wrote in sql query as Getdate() for createDate field?

If I published my Asp.Net solution on a server and server date time is correct.
Now, When any user access that URL from LAN network on another PC and that PC date time is not correct.
In that case if I write
Insert Into tblComp(1,'XYZ','Jam',GETDATE()) in my query.Then which date time will be inserted.Server or PC(which have accessing that URL)
tblComp structure
********************
id int,
SName varchar(50),
SAdd varchar(50),
CreateDate Datetime
*********************
The query executes on the database server, the database server will provide its current date and time.
Please note that this date and time will be in whatever time zone the database server is in as well.
From the documentation of GETDATE():
Returns the current database system timestamp as a datetime value without the database time zone offset. This value is derived from the operating system of the computer on which the instance of SQL Server is running.
If, on the other hand, you actually want the local date and time of the client, you will have to provide that through a parameter. On an ASP.NET site, this is not all that easy because the "client code" will the ASP.NET application, running on the web server, so instead of the date and time of the database server you would effectively use the date and time of the web server.
To actually get the client date and time (that is, the local date and time of the computer running the web browser that is browsing the site), you would probably have to resort to javascript, though I'm completely unfamiliar with how you would do that.

How can i get client system current datetime from sql instance?

Sql server getdate() function fetch server current datetime, how can I get client system current datetime from sql server instance?.
One of our client using one database for multiple companies operating from different time zones, being a huge database with many tables, procedures, functions and the getdate() function is used as default value for many area.
You can't. The SQL Server doesn't know anything about the time where the client that called it is located.
Consider using getutcdate() instead. Use UTC exclusively in your database, then convert between time zones in the application layer.
If you feel you need to convert between time zones in the database itself, you will need a third-party solution, such as my SQL Server Time Zone Support package.
I have same problem. I found this link:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/290a0085-47a5-48ab-9557-1b59ee269a40/call-getdate-from-linked-server?forum=transactsql
declare #rmt_time datetime;
exec('SET ? = CURRENT_TIMESTAMP', #rmt_time OUTPUT) at [remote_server];
select CURRENT_TIMESTAMP as local_time, #rmt_time as rmt_time;
Hope this helps.

Mysql TimeStamp datatype

I am developing a asp.net web application with ado.net entity framework and MySQL as backend.
I have taken some columns in DB as timestamp datatype when I get date from DB these fields of timestamp datatype returns null. In application these fields are mapped as datetimeoffset.
See the accepted answer to this post
How to convert a Unix timestamp to DateTime and vice versa?
You need to adapt the timestamps into datetimeoffset objects in .net.

Resources