Get-Date
Get the current date and time
Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Get-Date
Returns a DateTime. -Format uses .NET format strings. yyyy-MM-dd is the one you want in file names.
Try this
Get-Date
(Get-Date).AddDays(-7)
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | date '+%Y-%m-%d %H:%M:%S' |
| cmd.exe | echo %date% %time% |
More in From bash and From cmd.