Calculating using date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculating using date
# 1  
Old 01-28-2011
Calculating using date

I need to help to calculating using date in a script.
One application is licensed by date, some month at a time.
I can read the date from system and get an output like this:
echo $status
6A34 System4 01.01.11-31.01.11

My goal is to use license date 31.01.11 and subtract todays date 28.01.11 (using date function) and get value 3 in this example.
If value goes below 0, I then now I have a problem (using Munin to graph)
# 2  
Old 01-28-2011
Do you have the output you desire using date? You can customize date to return the format you desire using simple arguments. If date is in the format you want, I'm of no help. But if you're new like me then I can tell you date --help will help you with formatting. i personally use
Code:
date +%a%b%d%Y

in one of my scripts...which returns FriJan2011. So
Code:
date +%m%d%Y

would return 01282011 today. Might make the math easier...
# 3  
Old 01-28-2011
I know I can change the setting of date, but my problem is calculating in script.
I would like some like this
#!/bin/sh
value=echo $status | awk '{print $3}' | awk -F "-" '{print $2}'
dif=date-value

(my shell script knowledge are some limited)
# 4  
Old 01-28-2011
https://www.unix.com/unix-dummies-que...html#post16559

forgive me if this, yet again doesn't help, but I'm new and trying to give back. I saw this a little bit ago when searching google for a similar need
# 5  
Old 01-28-2011
Thank I will look at and see if I can figure out how it works
# 6  
Old 01-28-2011
Quote:
Originally Posted by Jotne
Thank I will look at and see if I can figure out how it works
If you have the datecalc script in your current directory (make it executable with chmod), you can subtract the dates like:
Code:
ldate=$(echo $status | awk -F"[.-]" '{print "20" $NF, $(NF-1), $(NF-2)}')
cdate=$(date +"%Y %m %d")

diff=$(./datecalc -a $cdate - $ldate)

echo $diff

# 7  
Old 01-28-2011
If your date command support -d option
Code:
t1=$(status|awk -F \- '{split($NF,a,"."); system("date -d "a[3]a[2]a[1]" +%s")}' )
today=$(date +%y%m%d)
t2=$(date -d "$today" +%s)

Code:
$ awk -v end=$t1 -v start=$t2 'BEGIN{print (end-start)/24/3600}' 

3

or

Code:
$ let d=($t1-$t2)/24/3600
$ echo $d
3

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grouping and Calculating

Hi All, I want to read the input file and store the output in the Output file. I pasted the sample Input and Output file below. Help me with this. Input file ================================= ITEM1 AAAAA 1 ITEM1 BBBBB 1 ITEM1 CCCCC 1 ITEM2 AAAAA 5 ITEM2 CCCCC 4... (1 Reply)
Discussion started by: humaemo
1 Replies

2. Shell Programming and Scripting

Calculating mean for samples 1-3 4-6 etc.

Hi. I have a LOOONG list of samples but I am not sure how to write the loop/script to calculate the mean... I normally use awk... ...................MEAN Sample1 25.82 40.61333 Sample1 47.6 Sample1 48.42 Sample2 54.03 54.12 Sample2 53.98 Sample2 54.35 etc..... I would like to... (4 Replies)
Discussion started by: danieladna
4 Replies

3. Shell Programming and Scripting

Calculating the epoch time from standard time using awk and calculating the duration

Hi All, I have the following time stamp data in 2 columns Date TimeStamp(also with milliseconds) 05/23/2012 08:30:11.250 05/23/2012 08:30:15.500 05/23/2012 08:31.15.500 . . etc From this data I need the following output. 0.00( row1-row1 in seconds) 04.25( row2-row1 in... (5 Replies)
Discussion started by: ks_reddy
5 Replies

4. Shell Programming and Scripting

Calculating expiry date using date,sed,grep

Hi, I would greatly appreciate it if someone can help me with my problem. I have a crawler which collects spam URLs everyday & this data needs to be published in a blacklist. Here's the catch: The "Time To Live" (TTL) for each URL is 3 months (or whatever for that matter). If i see the... (5 Replies)
Discussion started by: r4v3n
5 Replies

5. 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

6. UNIX and Linux Applications

sqlite: calculating with dates - compare current date minus 6 months with stored record

Hi I have a table with name, date in format DD.MM.YYYY. I need to something like this (I try to explain in pseudo code) if SYSDATE (current date) minus 6 months > $expiry date print OK else print NOK with $name and $expiry date I know this is possible with Oracle. How to do this... (0 Replies)
Discussion started by: slashdotweenie
0 Replies

7. UNIX for Dummies Questions & Answers

Calculating average

Hi, i have 12 float variables in a bash file and i want to calculate the average of them. Can any body help? (6 Replies)
Discussion started by: limadario
6 Replies

8. UNIX and Linux Applications

Calculating age from date of birth

MySQL... Given a column containing people's dates of birth, what's the best way to create a computed column giving their age in years...I can't find a suitable date/time function that'll do the job! :( (4 Replies)
Discussion started by: JerryHone
4 Replies

9. Shell Programming and Scripting

calculating in MB

hi all, have got a ksh script which tries to monitor memory usage of app servers. i do a ps -0 rss -p <PID> to get the memory size in KB but when i divide by 1024 to convert to MB i dont know how to round it up ?? thanks in advance. (3 Replies)
Discussion started by: cesarNZ
3 Replies

10. Shell Programming and Scripting

calculating a number

Hello all :) I need some help; I'm running the sp_spaceused command on various tables and saving the output to a file. So, I have an input file that has 3 rows - each row has 7 columns. I would like to 1) sort the file on the 4th column, 2) take the 4th column in the first row and add 25% to... (2 Replies)
Discussion started by: stonemonolith
2 Replies
Login or Register to Ask a Question