Evaluator Column - Precise Ages

Converting the Column - Age script to evaluator columns as they are much quicker.

These three columns provide Age Modified, Age Created, and Age Accessed in YY:DDD:HH:MM:SS format, respectively.

EDIT: updated based on @lxp's excellent - and brief - code down thread.

AGE MODIFIED:

<?xml version="1.0"?>
<evalcolumn align="0" attrrefresh="yes" autorefresh="yes" customgrouping="no" foldertype="all" header="P-Age [Mod]" keyword="PAgeMod" maxstars="5" namerefresh="no" nocache="no" reversegroups="no" reversesort="no" supportmarkup="no" title="Precise Age - Modified" type="7">secs = Age(modifieddate, &quot;s&quot;);

ss = secs Mod 60                 As &quot;#2&quot;;
mm = secs / 60 Mod 60            As &quot;#2&quot;;
hh = secs / 60 / 60 Mod 24       As &quot;#2&quot;;
dd = secs / 60 / 60 / 24 Mod 365 As &quot;#3&quot;;
yy = secs / 60 / 60 / 24 / 365   As &quot;#2&quot;;

return yy + &quot;:&quot; + dd + &quot;:&quot; + hh + &quot;:&quot; + mm + &quot;:&quot; + ss;</evalcolumn>
Longer version for educational purposes
<?xml version="1.0"?>
<evalcolumn align="2" attrrefresh="no" autorefresh="no" category="date" customgrouping="no" foldertype="all" graphbehind="3" header="Age [Mod - y:d:h:m:s]" keyword="AgeModifiedExact" maxstars="5" namerefresh="no" nocache="no" reversegroups="no" reversesort="no" supportmarkup="no" title="Age [Modified - Exact]" type="0" widthpx="150">if (operation == &quot;sort&quot;)
	return modifieddate; // Enable sorting by generic modifieddate

secs = Abs(DateDiff(&quot;s&quot;, Now(), modifieddate)); // Get difference in seconds between current second and second folder/file was last modified

s = secs Mod 60; 
m = secs / 60 Mod 60;
h = secs / 60 / 60 Mod 24;
d = secs / 60 / 60 / 24 Mod 365;
y = secs / 60 / 60 / 24 / 365;

// SECONDS
if (s == 0) ss = &quot;00&quot;;
elseif (s &lt; 10) ss = &quot;0&quot; + s; // 0 &lt; s &lt; 10
else ss = s; // s &gt; 9

// MINUTES 
if (m == 0) mm = &quot;00&quot;;
elseif (m &lt; 10) mm = &quot;0&quot; + m; // 0 &lt; m &lt; 10
else mm = m; //m &gt; 9

// HOURS
if (h == 0) hh = &quot;00&quot;;
elseif (h &lt; 10) hh = &quot;0&quot; + h; // 0 &lt; h &lt; 10
else hh = h; // h &gt; 9

// DAYS
if (d == 0) dd = &quot;000&quot;;
elseif (d &lt; 10) dd = &quot;00&quot; + d; // 0 &lt; d &lt; 10
elseif (d &lt; 100) dd = &quot;0&quot; + d; // 9 &lt; d &lt; 100
else dd = d; // h &gt; 99

// YEARS
if (y == 0) yy = &quot;00&quot;;
elseif (y &lt; 10)	yy = &quot;0&quot; + y; // 0 &lt; y &lt; 10
else yy = y; // y &gt; 9

return Trim(yy + &quot;:&quot; + dd + &quot;:&quot; + hh + &quot;:&quot; + mm + &quot;:&quot; + ss); // yy:ddd:hh:mm:ss</evalcolumn>

AGE CREATED:

<?xml version="1.0"?>
<evalcolumn align="0" attrrefresh="yes" autorefresh="yes" customgrouping="no" foldertype="all" header="P-Age [Cre]" keyword="PAgeCre" maxstars="5" namerefresh="no" nocache="no" reversegroups="no" reversesort="no" supportmarkup="no" title="Precise Age - Created" type="7">secs = Age(createddate, &quot;s&quot;);

ss = secs Mod 60                 As &quot;#2&quot;;
mm = secs / 60 Mod 60            As &quot;#2&quot;;
hh = secs / 60 / 60 Mod 24       As &quot;#2&quot;;
dd = secs / 60 / 60 / 24 Mod 365 As &quot;#3&quot;;
yy = secs / 60 / 60 / 24 / 365   As &quot;#2&quot;;

return yy + &quot;:&quot; + dd + &quot;:&quot; + hh + &quot;:&quot; + mm + &quot;:&quot; + ss;</evalcolumn>
Longer version for educational purposes
<?xml version="1.0"?>
<evalcolumn align="2" attrrefresh="yes" autorefresh="yes" category="date" customgrouping="no" foldertype="all" header="Age [Cre - y:d:h:m:s]" keyword="AgeCreatedExact" maxstars="5" namerefresh="yes" nocache="no" reversegroups="no" reversesort="no" supportmarkup="no" title="Age [Created - Exact]" type="0">if (operation == &quot;sort&quot;)
	return createddate; // Enable sorting by generic modifieddate

secs = Abs(DateDiff(&quot;s&quot;, Now(), createddate)); // Get difference in seconds between current second and second folder/file was last created

s = secs Mod 60; 
m = secs / 60 Mod 60;
h = secs / 60 / 60 Mod 24;
d = secs / 60 / 60 / 24 Mod 365;
y = secs / 60 / 60 / 24 / 365;

// SECONDS
if (s == 0) ss = &quot;00&quot;;
elseif (s &lt; 10) ss = &quot;0&quot; + s; // 0 &lt; s &lt; 10
else ss = s; // s &gt; 9

// MINUTES 
if (m == 0) mm = &quot;00&quot;;
elseif (m &lt; 10) mm = &quot;0&quot; + m; // 0 &lt; m &lt; 10
else mm = m; //m &gt; 9

// HOURS
if (h == 0) hh = &quot;00&quot;;
elseif (h &lt; 10) hh = &quot;0&quot; + h; // 0 &lt; h &lt; 10
else hh = h; // h &gt; 9

// DAYS
if (d == 0) dd = &quot;000&quot;;
elseif (d &lt; 10) dd = &quot;00&quot; + d; // 0 &lt; d &lt; 10
elseif (d &lt; 100) dd = &quot;0&quot; + d; // 9 &lt; d &lt; 100
else dd = d; // h &gt; 99

// YEARS
if (y == 0) yy = &quot;00&quot;;
elseif (y &lt; 10)	yy = &quot;0&quot; + y; // 0 &lt; y &lt; 10
else yy = y; // y &gt; 9

return Trim(yy + &quot;:&quot; + dd + &quot;:&quot; + hh + &quot;:&quot; + mm + &quot;:&quot; + ss); // yy:ddd:hh:mm:ss</evalcolumn>

AGE ACCESSED:

<?xml version="1.0"?>
<evalcolumn align="0" attrrefresh="yes" autorefresh="yes" customgrouping="no" foldertype="all" header="P-Age [Acc]" keyword="PAgeAcc" maxstars="5" namerefresh="no" nocache="no" reversegroups="no" reversesort="no" supportmarkup="no" title="Precise Age - Accessed" type="7">secs = Age(accesseddate, &quot;s&quot;);

ss = secs Mod 60                 As &quot;#2&quot;;
mm = secs / 60 Mod 60            As &quot;#2&quot;;
hh = secs / 60 / 60 Mod 24       As &quot;#2&quot;;
dd = secs / 60 / 60 / 24 Mod 365 As &quot;#3&quot;;
yy = secs / 60 / 60 / 24 / 365   As &quot;#2&quot;;

return yy + &quot;:&quot; + dd + &quot;:&quot; + hh + &quot;:&quot; + mm + &quot;:&quot; + ss;</evalcolumn>
Longer version for educational purposes
<?xml version="1.0"?>
<evalcolumn align="2" attrrefresh="no" autorefresh="no" category="date" customgrouping="no" foldertype="all" header="Age [Acc - y:d:h:m:s]" keyword="AgeAccessedExact" maxstars="5" namerefresh="no" nocache="no" reversegroups="no" reversesort="no" supportmarkup="no" title="Age [Accessed - Exact]" type="0">if (operation == &quot;sort&quot;)
	return accesseddate;

date_now = Now();
when_accessed = accesseddate;

secs = Abs(DateDiff(&quot;s&quot;, date_now, when_accessed));

s = secs Mod 60;
m = secs / 60 Mod 60;
h = secs / 60 / 60 Mod 24;
d = secs / 60 / 60 / 24 Mod 365;
y = secs / 60 / 60 / 24 / 365;

//SECONDS
if (s == 0) ss = &quot;00&quot;;
elseif (s &lt; 10) ss = &quot;0&quot; + s;
else ss = s; // s &gt; 9

//MINUTES 
if (m == 0) mm = &quot;00&quot;;
elseif (m &lt; 10) mm = &quot;0&quot; + m;
else mm = m; //m &gt; 9

//HOURS
if (h == 0) hh = &quot;00&quot;;
elseif (h &lt; 10) hh = &quot;0&quot; + h;
else hh = h; // h &gt; 9

//DAYS
if (d == 0) dd = &quot;000&quot;;
elseif (d &lt; 10) dd = &quot;00&quot; + d;
elseif (d &lt; 100) dd = &quot;0&quot; + d;
else dd = d; //h &gt; 99

//YEARS
if (y == 0) yy = &quot;00&quot;;
elseif (y &lt; 10)	yy = &quot;0&quot; + y;
else yy = y; // y &gt; 9

return Trim(yy + &quot;:&quot; + dd + &quot;:&quot; + hh + &quot;:&quot; + mm + &quot;:&quot; + ss);</evalcolumn>

To use any of these columns, open Preferences > Evaluator Columns > Add.

1 Like

You could save a few lines by calculating the age with Age(), and zero-padding the results with As, e.g. dd = d As "#3";.

This is as slim as I can get it, but it is not as precise. Days, hours, minutes, and seconds are slightly off. What might I be missing?

<?xml version="1.0"?>
<evalcolumn align="0" attrrefresh="no" autorefresh="no" customgrouping="no" foldertype="all" header="Age [LXP]" keyword="AgeLXP" maxstars="5" namerefresh="no" nocache="no" reversegroups="no" reversesort="no" supportmarkup="no" title="Age (LXP)" type="0">

yy = Age(modifieddate, &quot;yyyy&quot;) As &quot;#2&quot;;
dd = (Age(modifieddate) Mod 365) As &quot;#3&quot;;
hh = (Age(modifieddate, &quot;h&quot;) Mod 24) As &quot;#2&quot;;
mm = (Age(modifieddate, &quot;n&quot;) Mod 60) As &quot;#2&quot;;
ss = (Age(modifieddate, &quot;s&quot;) Mod 60) As &quot;#2&quot;;

return yy + &quot;:&quot; + dd + &quot;:&quot; + hh + &quot;:&quot; + mm + &quot;:&quot; + ss;</evalcolumn>

Age() will return rounded values, so only seconds will always be correct for the intended purpose. Let's stay with your original formula and just apply the formatting:

secs = Age(modifieddate, "s");

ss = secs Mod 60                 As "#2";
mm = secs / 60 Mod 60            As "#2";
hh = secs / 60 / 60 Mod 24       As "#2";
dd = secs / 60 / 60 / 24 Mod 365 As "#3";
yy = secs / 60 / 60 / 24 / 365   As "#2";

return yy + ":" + dd + ":" + hh + ":" + mm + ":" + ss;
2 Likes

I believe this is two beverages of choice I owe you...

Thanks @lxp!

@Chuck

Do you have an updated version of Column - Age?

The short piece of code posted by @lxp (2 posts upwards) works perfect - just paste it in the evaluator code field (Settings > File Display Columns > Evaluator columns), give it the name “Age”, choose the category Date and Time.

I posted an update to the original script in that thread. Will be moving forward with this one.

I also updated the original post to reflect @lxp's wisdom.