Age based on minutes
-
Bart
- Posts: 96
- Joined: 05 Feb 2017 14:29
Age based on minutes
I use this script to show the age of the files in the custom column.
$diffH = datediff(property("#date.m", <cc_item>), , "h");
return regexreplace($diffH / 24, "[.,]\d+$") . " days";
But it does not differentiate between files within one day/hour. How to add the minutes factor?
Bart
$diffH = datediff(property("#date.m", <cc_item>), , "h");
return regexreplace($diffH / 24, "[.,]\d+$") . " days";
But it does not differentiate between files within one day/hour. How to add the minutes factor?
Bart
Highend outside this forum
-
highend
- Posts: 15004
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Age based on minutes
Real world example?But it does not differentiate between files within one day/hour. How to add the minutes factor?
Otherwise (wild guess):
Code: Select all
$diffH = datediff(property("#date.m", <cc_item>), , "n");
return regexreplace($diffH / (24 * 60), "[.,]\d+$") . " days";
One of my scripts helped you out? Please donate via Paypal
-
jupe
- Posts: 3478
- Joined: 20 Oct 2017 21:14
- Location: Win10 22H2 120dpi
Re: Age based on minutes
Another wild guess, if you mean you want hours (minutes?) displayed up until it is 24 hours old, something like this might work:
Code: Select all
$diffH = datediff(property("#date.m", <cc_item>), , "h");
if $diffH <= 24 { return $diffH . " hours";} else {
return regexreplace($diffH / 24, "[.,]\d+$") . " days";}-
Bart
- Posts: 96
- Joined: 05 Feb 2017 14:29
Re: Age based on minutes
What I mean is if there are a few files from the same day and I want to set them is the right order of age, the script reads the date and not till minutes. I want to list the files in age, even when there are a few minutes difference in modification date between the files.
Highend outside this forum
-
RalphM
- Posts: 2122
- Joined: 27 Jan 2005 23:38
- Location: Cairns, Australia
Re: Age based on minutes
Then sort the files by the regular date modified column and have the age column just sit there as info.
Ralph 
(OS: W11 25H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)
(OS: W11 25H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)
-
Bart
- Posts: 96
- Joined: 05 Feb 2017 14:29
Re: Age based on minutes
Yes, a logic that did not come into my mind, but workable indeed.
Highend outside this forum
-
Bart
- Posts: 96
- Joined: 05 Feb 2017 14:29
Re: Age based on minutes
Following the script from jupe, I try to make the following:
File age is mentioned in minutes if less than an hour
File age is mentioned in hours if less than an day
File age is mentioned in days for any other age
Something like this, but I failed to have it working:
$diffH = datediff(property("#date.m", <cc_item>), , "h");
if $diffH <= 24 { return $diffH . " hours";} else
if $diffH <= 1 regexreplace($diffH * 60, "[.,]\d+$") . " minutes";}
else
{
return regexreplace($diffH / 24, "[.,]\d+$") . " days";}
File age is mentioned in minutes if less than an hour
File age is mentioned in hours if less than an day
File age is mentioned in days for any other age
Something like this, but I failed to have it working:
$diffH = datediff(property("#date.m", <cc_item>), , "h");
if $diffH <= 24 { return $diffH . " hours";} else
if $diffH <= 1 regexreplace($diffH * 60, "[.,]\d+$") . " minutes";}
else
{
return regexreplace($diffH / 24, "[.,]\d+$") . " days";}
Highend outside this forum
-
klownboy
- Posts: 4469
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Re: Age based on minutes
I'm not sure if you had a unintentional return in the above when posting, but you can only have one "else" block and it must be last block in the control structure. Your first use of else should be "elseif" with the condition following it. I haven't looked at the rest of the code.
Code: Select all
elseif ($diffH <= 1) {regexreplace($diffH * 60, "[.,]\d+$") . " minutes";} //bracket your conditions for clarity
else ...-
Bart
- Posts: 96
- Joined: 05 Feb 2017 14:29
Re: Age based on minutes
Noted. I can't make it working as I am not strong in programming.
Highend outside this forum
-
klownboy
- Posts: 4469
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Re: Age based on minutes
Hi Bart, I think it's best, since you want a minutes return if less than an hour, to find the SC datedif in minutes first instead of hours and work up from there.
Code: Select all
$diffH = datediff(property("#date.m", <cc_item>), , "n");
if ($diffH <= 60) { //change to "<" instead of "<=" for 60 min to show as 1 hour instead of 60 minutes
return $diffH . " minutes";}
elseif ($diffH <= 1440) {
return regexreplace($diffH / 60, "[.,]\d+$") . " hours";}
else {
return regexreplace($diffH / 1440, "[.,]\d+$") . " days";}
-
highend
- Posts: 15004
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Age based on minutes
This wouldn't work, Ken. At least if I understand it correctly. He wants a correct sort order even if two files have only a difference in minutes but are e.g. both 1 day old.
So the outputformat must be something like: "days.hours.minutes" to support this...
So the outputformat must be something like: "days.hours.minutes" to support this...
One of my scripts helped you out? Please donate via Paypal
-
klownboy
- Posts: 4469
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Re: Age based on minutes
Hi highend, obviously I wasn't too sure of what Bart wanted. The above will give him the proper return for each file in minutes, hours, or days. So he'd have to reverse the order and sort it if his goal is to sort based on that particular column. As RalphM pointed out though, he can sort it based on a normal date column and show these returns in a independent column separately.
-
RalphM
- Posts: 2122
- Joined: 27 Jan 2005 23:38
- Location: Cairns, Australia
Re: Age based on minutes
With an ugly side effect that you would get/need a "00000 days 00 hours" for every file changed less than an hour ago, the double 00 and such probably being needed to make the sort really work, otherwise 10000, 1000, 100, 10, 1 days would all be sorted next to each other.
But it is Bart's decision which approach is preferred.
Ralph 
(OS: W11 25H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)
(OS: W11 25H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)
-
Bart
- Posts: 96
- Joined: 05 Feb 2017 14:29
Re: Age based on minutes
Thank you for helping me out, I started to learn how it works. I used the given solution and added some code for single/plural time periods and weeks.
Code: Select all
$diffH = datediff(property("#date.m", <cc_item>), , "n");
if ($diffH < 1) {
return $diffH . " minutes";}
elseif ($diffH < 2) {
return $diffH . " minute";}
elseif ($diffH < 60) {
return $diffH . " minutes";}
elseif ($diffH < 120) {
return regexreplace($diffH / 60, "[.,]\d+$") . " hour";}
elseif ($diffH < 1440) {
return regexreplace($diffH / 60, "[.,]\d+$") . " hours";}
elseif ($diffH < 2880) {
return regexreplace($diffH / 1440, "[.,]\d+$") . " day";}
elseif ($diffH < 10080) {
return regexreplace($diffH / 1440, "[.,]\d+$") . " days";}
elseif ($diffH < 20160) {
return regexreplace($diffH / 10080, "[.,]\d+$") . " week";}
else {
return regexreplace($diffH / 10080, "[.,]\d+$") . " weeks";}Highend outside this forum
-
highend
- Posts: 15004
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Age based on minutes
Why not like this?
Less repetition and the brain is normally able to get the correct context out of e.g. minute(s) by looking at the value
Code: Select all
$diffM = datediff(property("#date.m", <cc_item>), , "n");
if ($diffM < 60) { $time = $diffM . " minute(s)"; }
elseif ($diffM < 1440) { $time = ($diffM / 60) . " hour(s)"; }
elseif ($diffM < 10080) { $time = ($diffM / 1440) . " day(s)"; }
else { $time = ($diffM / 10080) . " week(s)"; }
return regexreplace($time, "[.,]\d+");
One of my scripts helped you out? Please donate via Paypal
XYplorer Beta Club