lundi 15 février 2021

How to do time "HH:mm" comparison in Powershell?

Apparently my code is like this and it is now working. I think the logic is already there. the $openTime and $closeTime is read from csv using import-csv in "HH:mm" form.

$openTime = $ip.openTime
$closeTime = $ip.closeTime
$time = Get-Date -UFormat "%R"

if (($time -ge $openTime) -and ($time -le $closeTime)) {
        Write-Host "Store is Open!" -ForegroundColor Green
}else{
        Write-Host "Store is outside open hours!" -ForegroundColor Red
}

Aucun commentaire:

Enregistrer un commentaire