Help with Sort Script (paid)

Hi everyone,

I’m somewhat new to coding in LUA. I just need to sort some data by date. I’ve attached what I have so far. I can sort by month but its not sorting by day.

I want to sort from newest to oldest. I’m sorting a lot of files so it needs to be fast.

I’m willing to pay you via paypal for your help.

The code is below.

local runAgain = false

local function sortTable(tbl)
for i = 2, #fileInfo -1 do
–keep a temporary backup
local temp = fileInfo[i];
–do checks
if fileInfo[i - 1].creationTime.year > fileInfo[i].creationTime.year and fileInfo[i - 1].creationTime.month > fileInfo[i].creationTime.month and fileInfo[i - 1].creationTime.day > fileInfo[i].creationTime.day and fileInfo[i - 1].creationTime.hour > fileInfo[i].creationTime.hour and fileInfo[i - 1].creationTime.min > fileInfo[i].creationTime.min and fileInfo[i - 1].creationTime.second > fileInfo[i].creationTime.second then
–swap items
fileInfo[i] = fileInfo[i - 1];
fileInfo[i - 1] = temp;
–set boolean
runAgain = true;
end
–reset
if i == #fileInfo -1 and runAgain == true then
i = 1;
runAgain = false;
break
end
end
end
[import]uid: 40156 topic_id: 10238 reply_id: 310238[/import]

I would do something like:

[lua]local function sortTable(tbl)
table.sort( tbl, function (a,b) return
((a.creationTime.year >= b.creationTime.year) and
(a.creationTime.month >= b.creationTime.month) and
(a.creationTime.day >= b.creationTime.day) and
(a.creationTime.hour >= b.creationTime.hour) and
(a.creationTime.min >= b.creationTime.min) and
(a.creationTime.second > b.creationTime.second))
end)
end[/lua]

I didn’t have time to test, but I think it will run as expected. You can just swap the a,b to b,a in the function to reverse the order. [import]uid: 26049 topic_id: 10238 reply_id: 37378[/import]