Solved

Convert datetime into hours

Posted on 2011-09-12
3
225 Views
Last Modified: 2012-05-12
Hi,

Below query returns if a backup hadn't occured in last 7 days. But my reuirement is to check for last 24 hours backup status. Please let me know, how to convert below query to check last 24 hours or 12 hours  or 6 hours back backup status.

SELECT  (SELECT   RTRIM(CONVERT(char(20), SERVERPROPERTY('machinename'))) + '_' + CONVERT(char(20), SERVERPROPERTY('instancename'))) as instance,
        sd.name as name,
        bs.type,
        bs.database_name,
        max(bs.backup_start_date) as last_backup,
        note = CASE
   WHEN max(bs.backup_start_date) < GETDATE() - 7 THEN 'ALERT'
   WHEN ISNULL(max(bs.backup_start_date),0) = 0 THEN 'ALERT'
   ELSE '---'
   END
FROM    master..sysdatabases sd
        Left outer join msdb..backupset bs on rtrim(bs.database_name) = rtrim(sd.name)
        left outer JOIN msdb..backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
        WHERE sd.name NOT LIKE '%tempdb%'
Group by sd.name,
        bs.type,
        bs.database_name
Order by sd.name,last_backup


Thanks in Advance.

0
Comment
Question by:sg05121983
  • 2
3 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 36524070
You can use DATEADD(HH, -24, GETDATE()) to check 24 hours ago.
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 250 total points
ID: 36524083
And consequently, you can replace -24 with whatever amount of hours less or more than the passed in date you want to use. So for example, 12 hours ago is DATEADD(HH, -12, GETDATE()).
0
 

Author Closing Comment

by:sg05121983
ID: 36534068
--
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now