locked
use powershell: how to compare with current date? RRS feed

  • Question

  • I use following link:

    https://gallery.technet.microsoft.com/scriptcenter/Get-SQL-Last-Backup-Report-f4d51026

    Need to compare $Database.LastBackupDate  with current date, if older than 1 day, I will add something to script.

    But how to code $Database.LastBackupDate 1 day older than current date? I don't know how to powershell..

    Is it like:

    $Database.LastBackupDate- Get date >1...? I am not sure here

    Friday, April 20, 2018 4:14 PM

All replies

  • Basic PowerShell.

    if($Database.LastBackupDate -lt [datetime]::Today.AddDays(-1))}
         # do something
    }


    \_(ツ)_/

    Friday, April 20, 2018 4:32 PM