Mysql TimeStamp datatype - asp.net

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.

Related

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.

SQlite3 — SQL datetime stamps

Am I right in thinking that SQL does intrinsically store a date/time stamp for each commit? i.e., that I have to allow for recording this information as part of my schema design?
It will take a certain amount of space to store this information explicitly (using CURRENT_TIMESTAMP or my own timestamp), and if there's a way of accessing comparable information in some internal database setting, I'd do that instead. I'm working with SQLite3 at the moment.
SQLite does not have any internal time stamps.
(SQLite database files do not even have any record of transaction once they are committed.)

Why is DateTime.Now off by 12 hours when using EF 4.3.1?

I have a datetime2 column configured by EF 4.3.1 code first. I just noticed that when I update my entity using DateTime.Now the value updated/inserted into SQL Server 2008 is off by 12 hours.
Any ideas where or why this is happening? The system time on my machine is correct and all of my stored procedures that I call directly and use GETDATE() work as expected.
Baffled.
One more thing to note. The DateTime is correct all the way before context.savechanges is called. Something EF is doing or the way EF is passing it to SQL Server is getting mixed up.
From MSDN: GETDATE() Returns the current database system timestamp as a datetime value without the database time zone offset.
Most likely the cause of your problem is related to it.

Store GMT dates on a US server

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

Resources