Sorting Date column of a Table

Sorting a Date column can be tricky at times. This is done by calculating the difference between the dates.

NOTE: You will get an error: The left-hand side of an arithmetic operation must be of type ‘any’, ‘number’, ‘bigint’ or an enum type when you do not add valueOf()

When by date is of Date type

new Date(objDate1).valueOf() - new Date(objDate2).valueOf()

When date is in dd/MM/yyyy format

new Date(objDate1.split('/')[2],objDate1.split('/')[1],objDate1.split('/')[0],0,0,0,0).valueOf() 
- 
new Date(objDate2.split('/')[2],objDate2.split('/')[1],objDate2.split('/')[0],0,0,0,0).valueOf()

Sorting statement for a column of a table

sorter: (a, b) => { return new Date(a.objDate1.split('/')[2],a.objDate1.split('/')[1],a.objDate1.split('/')[0],0,0,0,0).valueOf() - new Date(b.objDate1.split('/')[2],b.objDate1.split('/')[1],b.objDate1.split('/')[0],0,0,0,0).valueOf();},
sortDirections: ['ascend', 'descend',]
Power Platform Academy

Start or Upgrade your Career with Power Platform

Learn with Akanksha

Python | Azure | AI/ML | OpenAI | MLOps

Design a site like this with WordPress.com
Get started