Page 1 of 1
How to: Retrieve the Number of Days Old a file is.
Posted: 22 Sep 2009 19:29
by timhatz
I would like to have a variable hold the number of days a file was last modified or when created.
I'm assuming, I grab a Property and then convert it, but I don't know how.
Please help.
Thanks, Tim
Re: How to: Retrieve the Number of Days Old a file is.
Posted: 22 Sep 2009 20:34
by admin
timhatz wrote:I would like to have a variable hold the number of days a file was last modified or when created.
I'm assuming, I grab a Property and then convert it, but I don't know how.
Please help.
Thanks, Tim
Unless you write a script for it: not possible. But if I add a new function DateDiff to scripting, it would be a very simple script to write: in poor man's code:
Code: Select all
daysold = datediff(now, modifieddate, indays)
Re: How to: Retrieve the Number of Days Old a file is.
Posted: 22 Sep 2009 22:16
by TheQwerty
Well, perhaps this will help get you started...
Code: Select all
"Days Since &Created : age"
Global($year, $month, $day, $result);
$year = "<datec yyyy>";
$month = "<datec m>";
$day = "<datec d>";
Sub("_ToDays");
Sub("_daysSince");
Status("Created $result day(s) ago.");
"Days Since &Modified : lastMod"
Global($year, $month, $day, $result);
$year = "<datem yyyy>";
$month = "<datem m>";
$day = "<datem d>";
Sub("_ToDays");
Sub("_daysSince");
Status("Modified $result day(s) ago.");
"&Days Between Created and Modified : diff"
Global($year, $month, $day, $result);
//Modified
$year = "<datem yyyy>";
$month = "<datem m>";
$day = "<datem d>";
Sub("_ToDays");
$modDays = $result;
//Created
$year = "<datec yyyy>";
$month = "<datec m>";
$day = "<datec d>";
Sub("_ToDays");
if ($result > $modDays) { $result = $result - $modDays; }
else { $result = $modDays - $result; }
Status("Date Difference of $result day(s).");
"Convert Date to Days||4 : _ToDays"
Global($year, $month, $day, $result);
if ($month < 3) {
$month = $month + 12;
$year = $year - 1;
}
//GetToken is serving as a crude floor().
$a = GetToken($year/4, 1, ".");
$b = GetToken($year/100, 1, ".");
$c = GetToken($year/400, 1, ".");
$d = GetToken((153*$month+8)/5, 1, ".");
$result = 365*$year + $a - $b + $c + $day + $d;
"Calculate Days Since Date||4 : _daysSince"
Global($year, $month, $day, $result);
$days = $result;
$year = "<date yyyy>";
$month = "<date m>";
$day = "<date d>";
Sub("_ToDays");
if ($result > $days) { $result = $result - $days; }
else { $result = $days - $result; }
Status("$result day(s)");
Re: How to: Retrieve the Number of Days Old a file is.
Posted: 22 Sep 2009 23:11
by timhatz
I thank you for both, but If I could pick between admin's way or qwerty's way... I would go with Admin's way... But since that function does not exist (yet). I would have to go the really long way, unless the other function just happens to show up.
tim
Re: How to: Retrieve the Number of Days Old a file is.
Posted: 23 Sep 2009 11:00
by admin
timhatz wrote:I thank you for both, but If I could pick between admin's way or qwerty's way... I would go with Admin's way... But since that function does not exist (yet). I would have to go the really long way, unless the other function just happens to show up.
tim
I just added it. Sorry, TheQwerty!

Re: How to: Retrieve the Number of Days Old a file is.
Posted: 23 Sep 2009 18:37
by timhatz
Thanks for adding it..
tim