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

  • Question

  • I use following link:


    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