Date within a timeframe 2 days ago

How could I using the following example, change it to show 2 days ago within the same time frame 0600 AM to 0600 AM

let foo=`date "+(1%H-106)*60+1%M-100"` bar=foo+1440
find . -mmin +$foo -mmin -$bar | tr -s '/','-' '^' | cut -f2,3 -d"^" | tr -s '^' ' ' |
perl -e '@T=localtime(time-(2*86400));printf("%02d%02d%02d%02d%02d%02d\n",$T[5]+1900,$T[4]+1,$T[3],$T[2],$T[1],$T[0])'

oooh...

Sorry...mistook your request for a better way of getting today-2's timestamp. I'll keep thinking...

got anything in bash? not familar with perl

okay, so you're effectively looking to 'peg' the search timeframe to a specific window of time, as opposed to the default 24 hour window used by the find command? So, regardless of the time run, it would look only to the file stats managed between 6am and 6am...?

that is correct

Further to your previous posts it is slowly becoming clearer what you are trying to do. I don't think that the "let" line produces the values you expect.

The "find" syntax is definitely wrong.
The "tr" syntax is definitely wrong.
Please provide some sample filenames (or are they directory names?) showing what the filenames (or directory names?) will look like before and after processing.

I think that you mean that the day starts at 06:00:00 and ends at 05:59:59 the following calendar day.
Please give examples of what values you expect in $foo and $bar at say 05:58 and 06:02 on particular calendar days so as to clearly define "today" "yesterday" and "2 days ago".

An obvious idea would be to run the script from cron at 06:00 daily.

Another idea (having just read recent post). If your "find" has -mmin it must have -daystart. The whole process can be done in a single "find" with suitable constants for $foo and $bar regardless of what time it is. The only decision based on the time of day would be which pair of constants to use.

If you have gnu date, it's usable also in bash.

If you can use ksh93, then you can use printf %T.

Example 1,
Example2,
Example 3

Gnu date examples:

date +%Y-%m-%d --date='28 day ago'
date -d 'today 06:00:00' 
date '+%Y-%d-%m %H:%M' -d 'yesterday 06:00:00'

Gnudate and epoc:

epoc=$(date -u +%s)

echo $epoc
(( yesterday=epoc-86400 ))

datestr=$(date -d "1970-01-01  $epoc seconds"  )
echo  $datestr
datestr=$(date -d "1970-01-01  $epoc seconds" '+%Y-%m-%d %H:%M:%S' )
echo  $datestr
echo "yesterday:"
date -d "1970-01-01  $yesterday seconds" '+%Y-%m-%d %H:%M:%S'

I do see a potential need for this sort of peg approach, especially if even a cron job misses or similar; or you'd need to just re-do the job. It would allow you to rely on a fixed timeframe, but methyl's point is well-taken since your point in the day would also need to be pegged to a difference between now and 6am.

A better approach would probably be to dummy up your timestamps and then use these within your find query string; I've always needed (and done) this in SQL, but I've never hunkered down to do it within the shell for files. I'm on Solaris, so GNU date is not an option, I'm using the standard issue ksh88 (on Solaris 10) or ksh93 (on Windows) and perl is not a viable option for the OP. So the question is really more over basic portability: can the shell manage a suitable date calculation method? And if it can, what's the most portable approach across the various shells?

Okay, so if you were able to pony up a reliable calculation of today's date-1 and date-2 (or better yet...any date-1 and date-2 args, to allow for any sort of catch-up situation...), you could effectively dummy up a timestamp and touch two files for use within the find command to use a query against -newer $date-1 and ! -newer $date-2. Since the available options will vary by your platform and/or shell, the components may vary, but the results shouldn't. Based on your original find command query's use of -mmin, it looks like you're either GNU or ksh93-based, so you might be able to use kshji's -d option, but this is more of a mental exercise for me. (I'd argue using perl is good for you, but there are many ways to get the required results.)

I'll take the wimp's way out for the moment and propose a pseudocode theory as opposed to actual code here, since I am crunched for time today, but the basic premise is as follows. (I'll provide actual code at some point, if I get a chance):

0) Calculate your timespan based on arguments to a function/script (ie, 2 and 1 to achieve two days ago and one day ago, etc);
-> this allows for flexibility in terms of days back, etc. (Can be expanded to apply to the specific timestamp as well...)

1) Take those calculated dates and dummy them up into a touch command such as follows:
-> note the use of literals in the timestamps, which allows for the inclusion of another variable-driven value;

         touch /tmp/beg_date.txt 
         touch /tmp/end_date.txt 
         touch -m ${1:-$(date +%m%d0600)} /tmp/beg_date.txt    #  $1 = MMDDHHmm 
         touch -m ${2:-$(date +%m%d0559)} /tmp/end_date.txt    #  $2 = MMDDHHmm 
   

2) Modify your find command to reflect these bookend files in your query:

         find . -newer /tmp/beg_date.txt -a ! -newer /tmp/end_date.txt | ... 
   

I'd also recommend the following link with regard to going about actually calculating the days back value(s), since this would be specific to your platform and/or preferences (http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html)