Increase the number every day

I am sure it is very easy, but I am at a dead end.

I need to create a variable in PowerShell that grows every day. I will use this variable in the email to determine the day number as part of the testing schedule. for example "Test - Day 38", when the next day the script should be ready "Test - Day 39".

Obviously, I cannot use the date and AddDays, because the number is not limited to the number of days in a month.

Please, help.

+3
source share
2 answers

Here is the code $days- the result

# when counting starts, the first day
$startDate = [datetime]'2014-01-12'

# elapsed days (+ 1 in order to start with "day 1")
$days = [int]((Get-Date) - $startDate).TotalDays + 1

# result string
"Test - Day $days"

This code outputs (today)

Test - Day 38
+3
source

Here I suggest (cmdlets are involved date):

  • . :

    if (!(Test-Path startTime.txt)) {
        get-date | out-file startTime.txt
    }
    
  • , , first_runtime .

  • ( get-date) first_runtime.
  • .Days, , .

    Days              : 2
    Hours             : 0
    ...
    
+1

All Articles