开发者

How can I use get-date to change the month while controlling the format in Powershell

开发者 https://www.devze.com 2023-03-20 12:38 出处:网络
I just started working 开发者_运维知识库with Powershell and I am trying to manipulate a date such that I add two months to the date and set it as a var.Powershell handles this nicely and even handles

I just started working 开发者_运维知识库with Powershell and I am trying to manipulate a date such that I add two months to the date and set it as a var. Powershell handles this nicely and even handles year rollover. However I am stuck trying to figure out how to also control the format of the date before, during or after adding two months to the date. Both of the statements below give me what I want but i have not been able to figure out how to combine them.

$ndate = (Get-Date).AddMonths(2)

$exp = date -format MM/dd/yyyy

Thank you,


Get-Date (Get-Date).AddMonths(2) -f MM/dd/yyyy

When the -Format operator is not avaiable you can use the ToString method:

(Get-Date).AddMonths(2).ToString('MM/dd/yyyy')
0

精彩评论

暂无评论...
验证码 换一张
取 消