# LastWriteTime vs LastWriteTime.Year

**URL:** <https://forums.powershell.org/t/lastwritetime-vs-lastwritetime-year/22477>\
**Category:** PowerShell Help\
**Created:** [June 18, 2023, 8:10pm UTC](https://forums.powershell.org/t/lastwritetime-vs-lastwritetime-year/22477 "2023-06-18T20:10:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![novumPS](https://avatars.discourse-cdn.com/v4/letter/n/a698b9/32.png) [@novumPS](https://forums.powershell.org/u/novumPS)\
**Post date:** [June 18, 2023, 8:10pm UTC](https://forums.powershell.org/t/lastwritetime-vs-lastwritetime-year/22477/1 "2023-06-18T20:10:44Z")

</div>

This is a (really) basic question… I have only just learnt to spell PowerShell.  
It is a fundamental that is tripping me up… will seem like a simple matter, and I am looking more towards a conceptual answer.

“gci -file ! select Fullname, LastWriteTime | ft” will return the full filespec and the last modified date and time.

“gci -file ! select Fullname, LastWriteTime.year | ft” will return the full filespec and nothing else.

…but I can use LastWriteTime.year successfully in a script to give me the year a file was last updated.  
What am I missing? (told you it was basic!)

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [June 19, 2023, 2:06pm UTC](https://forums.powershell.org/t/lastwritetime-vs-lastwritetime-year/22477/2 "2023-06-19T14:06:47Z")

</div>

Not 100% but Select-Object can only query properties (LastWriteTime) of a supplied object and not nested object properties. LastWriteTime is also an object with properties

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [June 19, 2023, 2:09pm UTC](https://forums.powershell.org/t/lastwritetime-vs-lastwritetime-year/22477/3 "2023-06-19T14:09:55Z")

</div>

You can either extract the year as you were (the more basic approach) or you can use a feature called calculated properties. Looks something like this  
`gci | select FullName, @{name="LastWriteYear";e={$_.LastWriteTime.year}`

> **[about Calculated Properties - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_calculated_properties?view=powershell-7.3)**
>
> PowerShell provides the ability to dynamically add new properties and alter the formatting of objects output to the pipeline.

---

<div class="post-metadata">

**Author:** ![novumPS](https://avatars.discourse-cdn.com/v4/letter/n/a698b9/32.png) [@novumPS](https://forums.powershell.org/u/novumPS)\
**Post date:** [June 20, 2023, 9:49pm UTC](https://forums.powershell.org/t/lastwritetime-vs-lastwritetime-year/22477/4 "2023-06-20T21:49:30Z")

</div>

Thanks neemobeer (like the name)… and it works… but I’m not getting the concept of “nested object properties”.

The answer is good… I will keep it in mind as I get more experience and (hopefully) these concept pieces will fall into place. I will also play with “calculated properties” as a way to convince select that I am giving it what it wants/needs.

Cheers

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/lastwritetime-vs-lastwritetime-year/22477/5 "2024-05-16T20:14:49Z")

</div>

Closed on May 16, 2024, 8:14pm UTC


