sql-serveru-sql

How to parse the query to hours instead of days in usql


I need to update logic to add buffer to to do data for last 24 hours instead of 7 days

DECLARE @todo = @opinion== 0? DateTime.UtcNow.AddDays( - 7) : new DateTime(@opinion);

Tried this with offset but it didn't work for me.

DECLARE @todo = @opinion== 0? DateTime.UtcNow.AddDays(-7) : new DateTimeOffset(@opinion, DateTime.UtcNow.AddHours(-24));

Solution

  • opinion is within the last 7 hours

    DECLARE @opinion = DateTime.UtcNow.AddHours(-9);
    
    SELECT ...
    WHERE opinion >=  DateTime.UtcNow.AddHours(-7) AND opinion <= DateTime.UtcNow;
    

    Missing details for a complete answer.