|
|
Question : DateDiff Minute GetDate Between C# vs SQL
|
|
I've been using the following C#/SQL combo to get a solution. It works as-is but I would like to have a pure-SQL solution if possible.
[C#/SQL Combo] string strCurrentTimeOnly = DateTime.Now.ToShortTimeString(); // 10:17 AM string strDayofWeek = DateTime.Now.DayOfWeek.ToString(); // Thursday string sql = " Select * from tbl_Users where col3 = 'True' " + " and DateDiff(n, col_TimeOnly, '" + strCurrentTimeOnly + "') between 1 and 1 " + " Or col_DayOfWeek = '" + strDayOfWeek + "')";
[SQL using GetDate()] " Select * from tbl_Users where col3 = 'True' " + " and DateDiff(minute, col_TimeOnly, GetDate()) between 1 and 1 " + " Or col_DayOfWeek = '" + strDayOfWeek + "')";
The SQL above returns nothing... I think the problem is GetDate() represents datetime and not just time only ....
Help...
|
Answer : DateDiff Minute GetDate Between C# vs SQL
|
|
So, now it is a datetime in SQL, can now do a similar thing:
Select * from tbl_Users where col3 = '1' and dateDiff(mm, col_TimeOnly, getdate()) = 1
not sure what the "between" is trying to achieve, so the = 1 above might need to be different...
|
|
|
|
|