How to: Retrieve the Number of Days Old a file is.

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
timhatz
Posts: 41
Joined: 12 Dec 2008 06:21

How to: Retrieve the Number of Days Old a file is.

Post 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

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.

Post 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)

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: How to: Retrieve the Number of Days Old a file is.

Post 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)");

timhatz
Posts: 41
Joined: 12 Dec 2008 06:21

Re: How to: Retrieve the Number of Days Old a file is.

Post 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

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.

Post 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! :wink:

timhatz
Posts: 41
Joined: 12 Dec 2008 06:21

Re: How to: Retrieve the Number of Days Old a file is.

Post by timhatz »

Thanks for adding it..

tim

Post Reply