0

I need to compare two dates that are on SQLServer, to see if the user has already logged after 10 seconds of his register on the system, but when I try this query, it gives me a

NotSupportedException [System.NotSupportedException] = {"System.DateTime AddSeconds(Double)"}

Query:

var query = from user in this.Query()
            where (user.LastLoginDate.AddSeconds(-10) <= user.CreateDate) 
            select std;
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
Saliba
  • 175
  • 2
  • 9
  • possible duplicate of [How to use DATEADD over column in LINQ - DateAdd is not recognized by LINQ](http://stackoverflow.com/questions/17371798/how-to-use-dateadd-over-column-in-linq-dateadd-is-not-recognized-by-linq) – Caramiriel Jan 16 '15 at 15:10
  • Linq-To-Sql or Linq-To-Entities? – Tim Schmelter Jan 16 '15 at 15:10
  • the problem is that I'm comparing two SQLDates. It is linq-to-sql – Saliba Jan 16 '15 at 15:12
  • This is a non-issue. In LINQ-to-SQL it's supported. It's not clear if OP have their tags right and below the accepted answer there is a vague comment "I managed to change the requirements". Voting to close as not reproducible. – Gert Arnold Jul 05 '21 at 11:04

1 Answers1

0

Well here is really dirty (and probably bad perfomance if you don't have indexes) way to solve your problem but it should work:

var query = from user in this.Query()
            where ((user.LastLoginDate.Date == user.CreateDate.Date
                && user.LastLoginDate.Hour == user.CreateDate.Hour
                && user.LastLoginDate.Minute == user.CreateDate.Minute
                && user.LastLoginDate.Second <= user.CreateDate.Second + 10)
                ||(user.LastLoginDate.Date == user.CreateDate.Date
                && user.LastLoginDate.Hour == user.CreateDate.Hour
                && user.LastLoginDate.Minute + 1 == user.CreateDate.Minute
                && 60 - user.CreateDate.Second + user.LastLoginDate.Second <= 10)) 
            select std;

I think you get the idea.

teo van kot
  • 12,350
  • 10
  • 38
  • 70