Table Date Sorting

Product: PowerShell Universal
Version: 2.8.1

Using the New-UDTableColumn -SortType datetime doesn’t seem to be sorting dates properly. I see no difference with or without the SortType.

$Data = @(
    @{Test = 'Data 123'; Date = Get-Date ((Get-Date).AddDays(-200)) -format 'MM/dd/yyyy'}
    @{Test = 'Data 045'; Date = Get-Date ((Get-Date).AddDays(-20)) -Format 'MM/dd/yyyy' }
    @{Test = 'Data 000'; Date = Get-Date ((Get-Date).AddDays(2)) -format 'MM/dd/yyyy' }
    @{Test = 'Data 901'; Date = Get-Date ((Get-Date).AddDays(-200)) -format 'MM/dd/yyyy' }
    @{Test = 'Data 800'; Date = Get-Date ((Get-Date).AddDays(2)) -format 'MM/dd/yyyy' }
)

$Columns = @(
    New-UDTableColumn -Property Test
    New-UDTableColumn -Property Date -SortType datetime
)

New-UDTable -Data $Data -Columns $Columns -ShowSort

2022-02-12_15-27-29

I can sort them properly from command-line
image

Using -Format will turn the date into a string and then the date sort type won’t work.

Try this:

$Data = @(
    @{Test = 'Data 123'; Date = Get-Date ((Get-Date).AddDays(-200))}
    @{Test = 'Data 045'; Date = Get-Date ((Get-Date).AddDays(-20)) }
    @{Test = 'Data 000'; Date = Get-Date ((Get-Date).AddDays(2))  }
    @{Test = 'Data 901'; Date = Get-Date ((Get-Date).AddDays(-200)) }
    @{Test = 'Data 800'; Date = Get-Date ((Get-Date).AddDays(2)) }
)

$Columns = @(
    New-UDTableColumn -Property Test
    New-UDTableColumn -Property Date -SortType datetime -Render {
        New-UDDateTime $EventData.Date -Format 'MM/DD/YYYY'
    }
)

New-UDTable -Data $Data -Columns $Columns -ShowSort
1 Like

I figured it had to do with the conversion to a string, but figured the sort type of datetime would be handling that. Thanks for the work around!