How get todays month value in powershell?

Product:

Microsoft PowerShell

Microsoft Windows 2019 Server

Issue:

How get the month value from datetime function in powershell?

Solution:

Enter a ps1 script like this:

# get today's day number: Get-Date -UFormat "%d"
# set month value in a variable: [String]$Manaden = (Get-Date -UFormat "%m")

[String]$Dagen = (Get-Date -UFormat "%d")
[String]$Manaden = (Get-Date -UFormat "%m")

# debug lines 
Write-Host [$Manaden]

 

UFormat specifiers to format the DateTime result of Get-Date in PowerShell. Return a formatted string and not a date object.

 

More information:

Get-Date – How to get and use Dates in PowerShell

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-variable?view=powershell-7.3 

https://devblogs.microsoft.com/scripting/use-powershell-to-work-with-any-ini-file/

https://ss64.com/ps/get-date.html