locked
declare first day in last month RRS feed

  • Question

  • Hi Team,

    Can some help me how to declare first day in last month in powershell 

    Wednesday, January 2, 2019 10:15 AM

Answers

  • DO you mean the first day of the previous month?

    $m = [datetime]::Today.Month
    $y = [datetime]::Today.Year
    [datetime]::New($y,$m,1).AddMonths(-1)

    Or ..

    [datetime]::New([datetime]::Today.Year, [datetime]::Today.Month, 1).AddMonths(-1)
    In date arithmetic the first day of the previous month is always one month less than the first day of the current month,


    \_(ツ)_/






    • Edited by jrv Wednesday, January 2, 2019 12:12 PM
    • Proposed as answer by BOfH-666 Wednesday, January 2, 2019 12:30 PM
    • Marked as answer by Richard MuellerMVP Wednesday, January 9, 2019 11:32 AM
    Wednesday, January 2, 2019 11:30 AM