Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-Date -UFormat %x does not match reference implementation #20979

Open
5 tasks done
Tracked by #20982
brianary opened this issue Dec 30, 2023 · 2 comments
Open
5 tasks done
Tracked by #20982

Get-Date -UFormat %x does not match reference implementation #20979

brianary opened this issue Dec 30, 2023 · 2 comments
Labels
Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Comments

@brianary
Copy link
Contributor

Prerequisites

Steps to reproduce

Get-Date -UFormat %x

Currently, "{0:MM/dd/yy}" is being used, but "{0:MM\/dd\/yy}" is a better match (though "{0:d}" is a reasonable match for the definition). See Date conversion specifiers or strftime.

Expected behavior

Based on running the `date -d $date +%x` as a reference implementation (see Environment for details).

PS> Get-Date 1999-01-01 -UFormat %x
01/01/99
PS> Get-Date 2000-02-14 -UFormat %x
02/14/00
PS> Get-Date 2001-03-29 -UFormat %x
03/29/01
PS> Get-Date 2002-05-12 -UFormat %x
05/12/02
PS> Get-Date 2003-06-25 -UFormat %x
06/25/03
PS> Get-Date 2004-08-07 -UFormat %x
08/07/04
PS> Get-Date 2005-09-20 -UFormat %x
09/20/05
PS> Get-Date 2006-11-03 -UFormat %x
11/03/06
PS> Get-Date 2007-12-17 -UFormat %x
12/17/07
PS> Get-Date 2009-01-29 -UFormat %x
01/29/09
PS> Get-Date 2010-03-14 -UFormat %x
03/14/10
PS> Get-Date 2011-04-27 -UFormat %x
04/27/11
PS> Get-Date 2012-06-09 -UFormat %x
06/09/12
PS> Get-Date 2013-07-23 -UFormat %x
07/23/13
PS> Get-Date 2014-09-05 -UFormat %x
09/05/14
PS> Get-Date 2015-10-19 -UFormat %x
10/19/15
PS> Get-Date 2016-12-01 -UFormat %x
12/01/16
PS> Get-Date 2018-01-14 -UFormat %x
01/14/18
PS> Get-Date 2019-02-27 -UFormat %x
02/27/19
PS> Get-Date 2020-04-11 -UFormat %x
04/11/20

Actual behavior

PS> Get-Date 1999-01-01 -UFormat %x
01-01-99
PS> Get-Date 2000-02-14 -UFormat %x
02-14-00
PS> Get-Date 2001-03-29 -UFormat %x
03-29-01
PS> Get-Date 2002-05-12 -UFormat %x
05-12-02
PS> Get-Date 2003-06-25 -UFormat %x
06-25-03
PS> Get-Date 2004-08-07 -UFormat %x
08-07-04
PS> Get-Date 2005-09-20 -UFormat %x
09-20-05
PS> Get-Date 2006-11-03 -UFormat %x
11-03-06
PS> Get-Date 2007-12-17 -UFormat %x
12-17-07
PS> Get-Date 2009-01-29 -UFormat %x
01-29-09
PS> Get-Date 2010-03-14 -UFormat %x
03-14-10
PS> Get-Date 2011-04-27 -UFormat %x
04-27-11
PS> Get-Date 2012-06-09 -UFormat %x
06-09-12
PS> Get-Date 2013-07-23 -UFormat %x
07-23-13
PS> Get-Date 2014-09-05 -UFormat %x
09-05-14
PS> Get-Date 2015-10-19 -UFormat %x
10-19-15
PS> Get-Date 2016-12-01 -UFormat %x
12-01-16
PS> Get-Date 2018-01-14 -UFormat %x
01-14-18
PS> Get-Date 2019-02-27 -UFormat %x
02-27-19
PS> Get-Date 2020-04-11 -UFormat %x
04-11-20

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

WSL Ubuntu details:

$ uname -a
Linux localhost 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Visuals

No response

@brianary brianary added the Needs-Triage The issue is new and needs to be triaged by a work group. label Dec 30, 2023
@237dmitry
Copy link

237dmitry commented Dec 31, 2023

date -d $date +%x as a reference implementation

%x 	Date in standard format for locale 	06/27/19 for English-US

Get-Date

From man date:

%x     locale's date representation (e.g., 12/31/99)

But it returns:

ss

@kilasuit kilasuit added the WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module label Jan 2, 2024
@brianary
Copy link
Contributor Author

brianary commented Jan 6, 2024

@237dmitry
Since it's locale-dependent, it could be due to your OS settings.
differing date output based on locale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module
Projects
None yet
Development

No branches or pull requests

3 participants