Forum Discussion
Tim Hunter
Jan 08, 2020Iron Contributor
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...
- 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
bake13
Microsoft
Jan 09, 2020Hi 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