I am new to YAML. I am trying to save Date/Time to a variable. and substract with 2000-01-01
. How can I do this. Finally it'll echo to console.
What I tried:
...
d1: $(Get-Date -Format "YYYYMMDD")
d2: $d1 - $(2000-01-01 -Format "YYYYMMDD")
steps:
- script: echo '$(d1)'
- script: echo '$(d2)'
I don't think there is a built-in date
variable/function but you could use PowerShell script to set the variables:
steps:
- pwsh: |
$d1 = Get-Date
$d2 = $d1 - (Get-Date -Year 2000 -Month 01 -Day 01)
Write-Host "##vso[task.setvariable variable=d1]$($d1.ToString("yyyyMMdd"))"
Write-Host "##vso[task.setvariable variable=d2]$($d2.Days)"
- pwsh: echo '$(d1)'
- pwsh: echo '$(d2)'