-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the current time of sql server? #4362
Comments
Until we have the ability to query for non-entity results (tracked by #1862) you would need to write something like this. var con = db.Database.GetDbConnection();
var cmd = con.CreateCommand();
cmd.CommandText = "SELECT GETDATE()";
con.Open();
var datetime = (DateTime)cmd.ExecuteScalar();
con.Close(); |
Closing this out as I think that answers your question and we already have #1862 tracking the feature that you really want in order to do this cleanly. Feel free to re-open if you disagree 😄. |
As a side note it is highly suggested to use UTC time instead of the local time by using |
Thank you very much! |
|
Hi,
In EF6, we get sql server current time, like this
DateTime currentDateTime = db.Database.SqlQuery ("SELECT GETDATE ();"). FirstOrDefault ();
But EF7, Database.SqlQuery does not exist, how to solve?
[Notes]
We can not use the following code:
DateTime currentDateTime = db.Users.Select (q => DateTime.Now) .FirstOrDefault ();
or
DateTime currentDateTime = db.Set () Select (q => DateTime.Now) .FirstOrDefault ().;
Since the beginning of our DbContext not contain any Entity, so ...how to solve?
thank you very much!
The text was updated successfully, but these errors were encountered: