Best-Killer Posted January 21, 2017 Share Posted January 21, 2017 Hello, how can I sort table date ! if we have in table 2017-01-21, 2017-01-22 and i draw them in dxtext for example .... it's will show like 2017-01-21 2017-01-22 i want it 2017-01-22 2017-01-21 Link to comment
iPrestege Posted January 21, 2017 Share Posted January 21, 2017 table.sort ( table, function ( a,b ) return a.value < b.value end ); -- or table.sort ( table, function ( a,b ) return a.value > b.value end ); You can do it like this. @Best-Killer < > Control them from the bigger to the smallest one. Link to comment
pa3ck Posted January 21, 2017 Share Posted January 21, 2017 local dates = { "2017-01-09", "2017-01-06", "2017-01-08", "2017-01-01" } table.sort ( dates, function ( a,b ) return a < b end ); for k, v in ipairs(dates) do print(v) end --Returns --2017-01-01 --2017-01-06 --2017-01-08 --2017-01-09 Link to comment
Best-Killer Posted January 21, 2017 Author Share Posted January 21, 2017 1 hour ago, iPrestege said: table.sort ( table, function ( a,b ) return a.value < b.value end ); -- or table.sort ( table, function ( a,b ) return a.value > b.value end ); You can do it like this. @Best-Killer < > Control them from the bigger to the smallest one. Thx Work For me ^^ 1 hour ago, pa3ck said: local dates = { "2017-01-09", "2017-01-06", "2017-01-08", "2017-01-01" } table.sort ( dates, function ( a,b ) return a < b end ); for k, v in ipairs(dates) do print(v) end --Returns --2017-01-01 --2017-01-06 --2017-01-08 --2017-01-09 Thanx too bro Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now