Forum Discussion

Tim Hunter's avatar
Tim Hunter
Iron Contributor
Jan 08, 2020
Solved

Counting Days

I have an SQL table that stores company incidents, so I have a Microsoft Flow that will send out an email with the count of days since the last incident. So basically, I want to know how many days it...
  • bake13's avatar
    Jan 09, 2020

    Hi Tim Hunter -- If your Incidents table contains a date field, you could use a query similar to the one below to calculate the number of days since the last incident was recorded.  Thanks.

    DECLARE @LastIncidentDate date = (SELECT MAX(IncidentDate) AS LastIncident FROM Incidents)
    DECLARE @CurrentDate date = (GETDATE())
    
    SELECT DATEDIFF(day, @LastIncidentDate, @CurrentDate) AS DaysWithoutAnIncident

Resources