Date Calculations


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Date Calculations
# 1  
Old 05-16-2006
Question Date Calculations

I need to be able to use the current date and calculate 7 days ago to be stored in another variable to be passed to a file in my Unix shell script. I need the date in the following format:

date '+%m/%d/%Y'
or
05/16/2006

How do I calculate date minus 7 days or 1 week ago?
# 2  
Old 05-16-2006
.... by reading the FAQs
# 3  
Old 06-01-2006
Data Doesn't work...

I read through the FAQs and still could not find a solution that works. One solution fails if the date is the 1st, like today (6/1/2006). I think that I'm going to have to go with another selection of using sqlplus to get the date from Oracle.
# 4  
Old 06-01-2006
Quote:
Originally Posted by mitschcg
I read through the FAQs and still could not find a solution that works. One solution fails if the date is the 1st, like today (6/1/2006). I think that I'm going to have to go with another selection of using sqlplus to get the date from Oracle.
Even none of those?
# 5  
Old 07-03-2008
Re: Date Calculations

hi there,
date -d '1 week ago'
or
date -d '7 days ago'
will give the date and time of exactly a week ago.
You can use '1 month ago' 'yesterday', '2 hours ago', etc..
For future dates, use 'tomorrow', '2 hours now', '1 week now', etc

Any date before/after any time period can be displayed this way.

Month=$(date -d '1 week ago' +%m)
Day=$(date -d '1 week ago' +%d)
Year=$(date -d '1 week ago' +%y)

echo $Month "/" $Day "/" $Year Smilie
# 6  
Old 07-03-2008
Quote:
Originally Posted by nayanasavio
hi there,
date -d '1 week ago'
or
date -d '7 days ago'
will give the date and time of exactly a week ago.
You can use '1 month ago' 'yesterday', '2 hours ago', etc..
For future dates, use 'tomorrow', '2 hours now', '1 week now', etc

Any date before/after any time period can be displayed this way.

Month=$(date -d '1 week ago' +%m)
Day=$(date -d '1 week ago' +%d)
Year=$(date -d '1 week ago' +%y)

echo $Month "/" $Day "/" $Year Smilie
this is GNU-ism and is not guaranteed to be installed.
# 7  
Old 03-06-2009
can anybody help me on this its urgent

i have a script named date1 with its content as follows:

echo "enter date:\c"
read date

if [ -z "$date" ]
then
echo "Please enter the date"
fi


now when the run the script and enter the date in say

05032009

then i want to print o/p as

05 March 2009

how do i do this

thanks,
haris
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Loop doing calculations

Hello. I'm writing an awk script that looks at a .csv file and calculates the weighted grade for each student based on the scores and categories in the file. I am able to get the script to run the only issue however is that the same score for each student is the same. I'm self-teaching myself the... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

Date wise calculations?

POST_DATE CHECK_NUMBER TYPE LOGIN_NAME 2015.09.09 XXXXXXXXXX mark XXXXXXXXXX 2015.09.09 XXXXXXXXXX fsadf XXXXXXXXXX 2015.10.05 XXXXXXXXXX defaa XXXXXXXXXX 2015.10.05 XXXXXXXXXX dewe XXXXXXXXXX 2015.10.06 XXXXXXXXXX dqwe XXXXXXXXXX 2015.09.14 XXXXXXXXXX dt4e XXXXXXXXXX... (22 Replies)
Discussion started by: nikhil jain
22 Replies

3. Shell Programming and Scripting

Output calculations

Attached are the is original output (zipped file) and a custom file using the awk code below in which the average reads per bait are calculated (average.txt) awk '{if(len==0){last=$4;total=$6;len=1;getline}if($4!=last){printf("%s\t%f\n", last,... (7 Replies)
Discussion started by: cmccabe
7 Replies

4. Shell Programming and Scripting

Problem with calculations

grep Quality abc.txt | awk -F"=" '{print $2}' o/p is given as 70/70 49/70 I want in the below format (percentage format) 100% 70% help me!!!!:confused::confused::confused: ---------- Post updated at 09:59 AM ---------- Previous update was at 09:57 AM ---------- Cell 01 -... (3 Replies)
Discussion started by: nikhil jain
3 Replies

5. UNIX for Dummies Questions & Answers

Doing calculations with bc on one field

Hello, I have to turn: Apple Inc.:325,64:329,57 into Apple Inc.:325,64:329,57:3,93 3,93=329,57-325,64. My code: cat beurs.txt | sed 's/\(*\):\(*\),*\(*\):\(*\),\(*\)/\4\.\5-\2\.\3/' beurs.txt | bc| tr '.' ',' | sed 's/^-*,/0,/' > winstmarges.txt; paste -d: beurs.txt winstmarges.txt; rm... (5 Replies)
Discussion started by: ikke008
5 Replies

6. Shell Programming and Scripting

Date Calculations using script!!

Hi all, Thanks in Advance , i am very new to programming part in script i think using some caluations+ sed command only we can do this process in script. for exampl: i have file in that one line is like this using sed i can replace the date and all but my requirement is The... (3 Replies)
Discussion started by: anishkumarv
3 Replies

7. UNIX for Dummies Questions & Answers

help with doing calculations on data

Dear All, I have a long list like this: 337 375 364 389 443 578 1001 20100 . . . . etc I would like to substract each value from the first entry which in this case is 337 and report it in a separate column. So the expected output looks like 337 0 (10 Replies)
Discussion started by: pawannoel
10 Replies

8. Shell Programming and Scripting

Need help with Date calculations in ksh

Hi Gurus, I am writing a script where we enter two dates, one a FROM DATE and the other a TO DATE. I need to validate that difference between the two dates is always less than or equal to 60 days. I could not find any date utility in ksh that could help me with this. Finally, I am deciding... (5 Replies)
Discussion started by: jidsh
5 Replies

9. UNIX for Dummies Questions & Answers

Time Calculations

I'm trying to have a loop print out statistics every X number of seconds. How can I add a specific number of seconds to a time variable and make a comparison? Thanks ahead of time. For example: startTime = `date +%H%M%S` currentTime = $startTime executeTime = startTime + X # X is equal... (5 Replies)
Discussion started by: Nysif Steve
5 Replies

10. UNIX for Dummies Questions & Answers

Float calculations

As expr is used for integer calculations, which command is used for float calculations. (1 Reply)
Discussion started by: sharmavr
1 Replies
Login or Register to Ask a Question