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
How to: Retrieve the Number of Days Old a file is.
-
admin
- Site Admin
- Posts: 64877
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: How to: Retrieve the Number of Days Old a file is.
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: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
Code: Select all
daysold = datediff(now, modifieddate, indays)FAQ | XY News RSS | XY X
Re: How to: Retrieve the Number of Days Old a file is.
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.
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
tim
-
admin
- Site Admin
- Posts: 64877
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: How to: Retrieve the Number of Days Old a file is.
I just added it. Sorry, TheQwerty!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
FAQ | XY News RSS | XY X
Re: How to: Retrieve the Number of Days Old a file is.
Thanks for adding it..
tim
tim
XYplorer Beta Club