# mocking Get-Date

**URL:** <https://forums.powershell.org/t/mocking-get-date/13542>\
**Category:** Pester\
**Created:** [December 16, 2019, 10:20am UTC](https://forums.powershell.org/t/mocking-get-date/13542 "2019-12-16T10:20:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nigelh](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@nigelh](https://forums.powershell.org/u/nigelh)\
**Post date:** [December 16, 2019, 10:20am UTC](https://forums.powershell.org/t/mocking-get-date/13542/1 "2019-12-16T10:20:21Z")

</div>

Hi,

I how can I mock Get-Date? below code does not work but if I change the mock commandname to Get-Test it works.

Should the below code work?

Thanks.

```
Function Get-Test {
Get-Date
}

Describe 'whatever' {
Context 'test getdate'{
it 'date should be dec1'{
$Date = Get-Date 12/01/2019
mock -CommandName Get-Date -MockWith {$Date}
Get-Test | Should -Be $Date
}
}
}
```

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [January 3, 2020, 12:39pm UTC](https://forums.powershell.org/t/mocking-get-date/13542/2 "2020-01-03T12:39:45Z")

</div>

Can you change the $Date variable to some other name and try ?

---

<div class="post-metadata">

**Author:** ![nigelh](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@nigelh](https://forums.powershell.org/u/nigelh)\
**Post date:** [January 5, 2020, 4:08pm UTC](https://forums.powershell.org/t/mocking-get-date/13542/3 "2020-01-05T16:08:02Z")

</div>

Thank you. works now. Not sure why it didn’t like $Date variable name.

---

<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, 9:13pm UTC](https://forums.powershell.org/t/mocking-get-date/13542/4 "2024-05-16T21:13:26Z")

</div>


