Date within a timeframe 2 days ago


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date within a timeframe 2 days ago
# 1  
Old 05-13-2010
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

Code:
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 '^' ' ' |

Moderator's Comments:
Mod Comment Please use code tags
# 2  
Old 05-13-2010
Code:
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...

Last edited by curleb; 05-13-2010 at 10:48 AM..
# 3  
Old 05-13-2010
got anything in bash? not familar with perl
# 4  
Old 05-13-2010
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...?
# 5  
Old 05-13-2010
that is correct
# 6  
Old 05-13-2010
Quote:
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 '^' ' ' |
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.

Last edited by methyl; 05-13-2010 at 12:21 PM..
# 7  
Old 05-13-2010
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:
Code:
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:
Code:
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'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get a given date and subtract it to 5 days ago

Hi all, I have been researching to obtain SSL certification expiry for most of our webistes. For some cases, some hosts where not directly accessible so i finally got a solution working with curl using my proxy. This lists the expiry date which i'm finally looking for. # curl --proxy... (4 Replies)
Discussion started by: nms
4 Replies

2. UNIX for Beginners Questions & Answers

How to find a file that's modified more than 2 days ago but less than 5 days ago?

How to find a file that's modified more than 2 days ago but was modified less than 5 days ago by use of any Linux utility ? (4 Replies)
Discussion started by: abdulbadii
4 Replies

3. Shell Programming and Scripting

Calculating 7 days ago date for the given Argument

Hi I have shell script and I am facing the below issue to integrate the date calculation to the the script. If I give the $1 as the date(20110701) then I need to get the 7 days ago date for the same format.(20110624). At first I thought its a simple one to handle and I did a search in the... (10 Replies)
Discussion started by: filter
10 Replies

4. UNIX for Advanced & Expert Users

N days ago

Hi, the following gives today $(date '+%d%m%y') For example 210111 for today (21 of january 2011). How can I have n days ego ? For example 160111 for 5 days ego ? thank you. (3 Replies)
Discussion started by: big123456
3 Replies

5. UNIX for Dummies Questions & Answers

Clarification on '1 days ago' in date command [Found answer, posted within]

I know the topic of getting yesterday's date has been covered ad nauseum, but I just want to be clear on something. I recently started using the command date --date='1 days ago' '+%m/%d/%y' to get yesterday's date and it's been working great. I just want to be certain that it is going to... (1 Reply)
Discussion started by: DeCoTwc
1 Replies

6. Shell Programming and Scripting

how to get what date was 28 days ago of the current system date IN UNIX

Hi, Anybody knows how to get what date was 28 days ago of the current system date through UNIX script. Ex : - If today is 28th Mar 2010 then I have to delete the files which arrived on 1st Mar 2010, (15 Replies)
Discussion started by: kandi.reddy
15 Replies

7. Shell Programming and Scripting

date for two days or 3 days ago

i need a script that can tell me the date 2 days ago or 3 days ago. please help (7 Replies)
Discussion started by: tomjones
7 Replies

8. Shell Programming and Scripting

Find the file from 15 days ago

How can I get difference date between today and 15 days ago and all filename is was created before 15 days ago? It has to be korn shell script. Thanks. (2 Replies)
Discussion started by: YoungBlood
2 Replies

9. UNIX for Dummies Questions & Answers

file was created before 15 days ago.

How can I get difference date between today and 15 days ago and all filename is was created before 15 days ago? It has to be korn shell script. Thanks. (1 Reply)
Discussion started by: YoungBlood
1 Replies

10. Shell Programming and Scripting

Function 7 days ago

Please tell me how can I wirte a function to return the date 7 days ago by using calendar command? :confused: (2 Replies)
Discussion started by: LAY
2 Replies
Login or Register to Ask a Question