Sponsored Content
Full Discussion: Date Substraction
Top Forums UNIX for Dummies Questions & Answers Date Substraction Post 1739 by mib on Wednesday 28th of March 2001 04:54:51 AM
Old 03-28-2001
Code:
#!/bin/bash

# figure out what yesterday was.
date '+%Y %m %d' |
 {
 read year month day

 day=`expr "$day" - 1`
 case "$day" in
 0)
 month=`expr "$month" - 1`
 case "$month" in
 0)
 month=12
 year=`expr "$year" - 1`
 ;;
 esac

 day=`cal $month $year | grep . | fmt -1 | tail -1`
 esac

 echo "Yeseterday was: $day $month $year"
                 }


Last edited by Yogesh Sawant; 05-20-2010 at 10:53 AM.. Reason: added code tags
 

9 More Discussions You Might Find Interesting

1. Solaris

Substraction in bash

Hi all, I have in one script something like this: FIRSTOCC=`grep -n ORA- alert_bill2.log |tail -"$ROWS"|head -1|cut -d: -f1` TOTAL=`more alert*|wc -l` DIFFERENCE=`$TOTAL-$FIRSTOCC` echo Total lines in alert_bill = $TOTAL echo $DIFFERENCE How do I make this substraction work? Thk (2 Replies)
Discussion started by: mclaudiu
2 Replies

2. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

3. Shell Programming and Scripting

date substraction

hello i have obtained the current date .. current_date=date "+%m/%d%y" and i have another date ,stored in my log file which i have already retrieved. i want to store the subtraction in a varible called diff. diff=log_date - currentdate ex: log_date=01/28/11 current_date=... (3 Replies)
Discussion started by: urfrnddpk
3 Replies

4. Shell Programming and Scripting

Problem in algebraic substraction

my code is like this count=`cat /filecount.txt | tail -1 |head -1| awk '{print $1}'` ###file is having value 264 #### echo "actual count = $count" exact_count=`expr $value \* 24` echo "exact_count= $exact_count" diff=`expr "$exact_count" - "$count"` a= exact_count - count ... (8 Replies)
Discussion started by: sagar_1986
8 Replies

5. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

6. Shell Programming and Scripting

Substraction in shell scripting

Hello friends, I am new on linux, i am facing issues on below script. #!/bin/sh current=1355147377 echo $current last_modified=1354537347 echo $last_modified DIFF='expr ($current - $last_modified)' echo $DIFF Please view this code tag video for how to use code tags when posting... (8 Replies)
Discussion started by: sanjay833i
8 Replies

7. Shell Programming and Scripting

Substraction of matching lines from a file.

I have 2 files: file1.txt contains /html/mybook/Charts/143712/reptiles.pdf /html/mybook/Charts/198459/spices.pdf /html/mybook/Charts/198459/fresh_nuts.pdf /html/mybook/Charts/123457/dome_anim.pdf /html/mybook/Charts/123457/vegetables.pdf /html/content/3DInteractive/174091/CSPSGGB.html ... (6 Replies)
Discussion started by: Jojan Paul
6 Replies

8. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

9. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies
CAL_TO_JD(3)								 1							      CAL_TO_JD(3)

cal_to_jd - Converts from a supported calendar to Julian Day Count

SYNOPSIS
int cal_to_jd (int $calendar, int $month, int $day, int $year) DESCRIPTION
cal_to_jd(3) calculates the Julian day count for a date in the specified $calendar. Supported $calendars are CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH and CAL_FRENCH. PARAMETERS
o $calendar - Calendar to convert from, one of CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH or CAL_FRENCH. o $month - The month as a number, the valid range depends on the $calendar o $day - The day as a number, the valid range depends on the $calendar o $year - The year as a number, the valid range depends on the $calendar RETURN VALUES
A Julian Day number. SEE ALSO
cal_from_jd(3), frenchtojd(3), gregoriantojd(3), jewishtojd(3), juliantojd(3), unixtojd(3). PHP Documentation Group CAL_TO_JD(3)
All times are GMT -4. The time now is 07:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy