Way to programmaticly retrieve a databases creation date and last backup date?

Last post 05-13-2008, 3:22 AM by eralper. 2 replies.
Sort Posts: Previous Next
  •  04-17-2008, 7:16 AM Post number 47711

    Way to programmaticly retrieve a databases creation date and last backup date?

    Hi there all.

    I need to fire specific events (like a database backup) after a certain number days. Let's say every 60 days. I need this to be based on firstly the date a database was created, so 60 days after that. Then once the database has been backed up, the last backup date needs to be used instead of the creation date.

    How can I programmticly get those two dates? I was wondering if there isn't maybe like a system stored proc like the one to check a databases allocated space and available space.

    Thanks in advance.

    Keith.

  •  05-08-2008, 1:58 PM Post number 51598 in reply to post number 47711

    Re: Way to programmaticly retrieve a databases creation date and last backup date?

    You don't need to. All you need to do is to use something like this...


    SELECT   DATEDIFF(DAY,create_date,GETDATE()) % 80
    FROM     sys.databases
    WHERE    name LIKE 'MyDatabase'

    ... and just do the backup when the result is zero, or whatever. Much simpler

  •  05-13-2008, 3:22 AM Post number 52744 in reply to post number 51598

    Re: Way to programmaticly retrieve a databases creation date and last backup date?

    If you want to take the database name automatically you can use db_name() as follows;

    SELECT
    DATEDIFF(dd, create_date, GETDATE())
    FROM sys.databases
    WHERE name = DB_NAME()


    Eralper
    http://www.kodyaz.com
    http://www.eralper.com
View as RSS news feed in XML