Home > front end >  Powershell | How to calculate current date -5 days to Epoch time?
Powershell | How to calculate current date -5 days to Epoch time?

Time:07-29

So I'm trying to write a script to get the current date and subtrace 5 days from it. Then change that date to Epoch time. However it's not really working out properly. I've currently been unable to subtract the 5 days from it, this is currently my script:

$unixTime = [int][double]::Parse((Get-Date -UFormat %s))
return $unixTime

I've also tried the following:

$unixTime = [int][double]::Parse(((Get-Date).AddDays(-5) -UFormat %s)))
return $unixTime

And also :

$unixTime = [int][double]::Parse((Get-Date) -UFormat %s).AddDays(-5))
return $unixTime

But so far I haven't been able to make it work. Does anyone know what I have to change about this calculation to make it work? Thank you very much!

CodePudding user response:

Would this be what you're after?

Get-Date $((Get-Date).AddDays(-5)) -UFormat  %s
  • Related