Get full Month Name from a files lastwritetime

How can I get the full month name in PowerShell (i.e. December) from the lastwritetime of a file I just retrieved?

$Dt = (c:\folder\transactionfile.txt).lastwritetime

From $Dt I need to get the month name.

July 31st, 2015 12:12pm

Get-Date $Dt -Format 'MMMM'

or

$Dt.ToString('MMMM')

This is a good article: Formatting Dates and Times
Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 12:25pm

Both of Leif-Arne's examples will get the full month name; however, the way you're setting your $Dt variable doesn't work for me. Is it possible you forgot the Get-ChildItem, or Get-Item, cmdlet? Should it have been $Dt = (Get-ChildItem c:\folder\transactionfile.txt).LastWriteTime?

July 31st, 2015 12:55pm

Thank you. Saw the article "Formatting Dates and Times" but missed the very last example.
Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 1:22pm

Your right. I had used a Get-Item about 5 lines earlier.
July 31st, 2015 1:36pm

Get-Date $Dt -Format 'MMMM'

or

$Dt.ToString('MMMM')

This is a good article: Formatting Dates and Times
Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 4:22pm

Both of Leif-Arne's examples will get the full month name; however, the way you're setting your $Dt variable doesn't work for me. Is it possible you forgot the Get-ChildItem, or Get-Item, cmdlet? Should it have been $Dt = (Get-ChildItem c:\folder\transactionfile.txt).LastWriteTime?

  • Proposed as answer by Mike Laughlin Friday, July 31, 2015 5:03 PM
July 31st, 2015 4:52pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics