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
HTML::CalendarMonth::DateTool(3pm)			User Contributed Perl Documentation			HTML::CalendarMonth::DateTool(3pm)

NAME
HTML::CalendarMonth::DateTool - Base class for determining which date package to use for calendrical calculations. SYNOPSIS
my $date_tool = HTML::CalendarMonth::DateTool->new( year => $YYYY_year, month => $one_thru_12_month, weeknum => $weeknum_mode, historic => $historic_mode, datetool => $specific_datetool_if_desired, ); DESCRIPTION
This module attempts to utilize the best date calculation package available on the current system. For most contemporary dates this usually ends up being the internal Time::Local package of perl. For more exotic dates, or when week number of the years are desired, other methods are attempted including DateTime, Date::Calc, Date::Manip, and the linux/unix 'ncal' or 'cal' commands. Each of these has a specific subclass of this module offering the same utility methods needed by HTML::CalendarMonth. METHODS
new() Constructor. Takes the following parameters: year Year of calendar in question (required). If you are rendering exotic dates (i.e. dates outside of 1970 to 2038) then something besides Time::Local will be used for calendrical calculations. month Month of calendar in question (required). 1 through 12. weeknum Optional. When specified, will limit class excursions to those that are currently set up for week of year calculations. historic Optional. If the the ncal or cal commands are available, use one of them rather than other available date modules since these utilities accurately handle some specific historical artifacts such as the transition from Julian to Gregorian. datetool Optional. Mostly for debugging, this option can be used to indicate a specific HTML::CalendarMonth::DateTool subclass for instantiation. The value can be either the actual utility class, e.g., Date::Calc, or the name of the CalendarMonth handler leaf class, e.g. DateCalc. Use 'ncal' or 'cal', respectively, for the wrappers around those commands. There are number of methods automatically available: month() year() weeknum() historical() datetool() Accessors for the parameters provided to "new()" above. dow1st() Returns the day of week number for the 1st of the "year" and "month" specified during the call to "new()". Relies on the presence of "dow1st_and_lastday()". Should be 0..6 starting with Sun. lastday() Returns the last day of the month for the "year" and "month" specified during the call to "new()". Relies on the presence of "dow1st_and_lastday()". Overridden methods Subclasses of this module must provide at least the "day_epoch()" and "dow1st_and_lastday()" methods. dow1st_and_lastday() Required. Provides a list containing the day of the week of the first day of the month (0..6 starting with Sun) along with the last day of the month. day_epoch() Optional unless interested in epoch values for wacky dates. For a given day, and optionally "month" and "year" if they are different from those specified in "new()", provide the unix epoch in seconds for that day at midnight. If the subclass is expected to provide week of year numbers, three more methods are necessary: dow() For a given day, and optionally "month" and "year" if they are different from those specified in "new()", provide the day of week number. (1=Sunday, 7=Saturday). add_days($days, $delta, $day, [$month], [$year]) For a given day, and optionally "month" and "year" if they are different from those specified in "new()", provide a list of year, month, and day once "delta" days have been added. week_of_year($day, [$month], [$year]) For a given day, and optionally "month" and "year" if they are different from those specified in "new()", provide a list with the week number of the year along with the year. (some days of a particular year can end up belonging to the prior or following years). AUTHOR
Matthew P. Sisk, <sisk@mojotoad.com> COPYRIGHT
Copyright (c) 2010 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
HTML::CalendarMonth(3), Time::Local(3), DateTime(3), Date::Calc(3), Date::Manip(3), cal(1) perl v5.12.4 2011-08-26 HTML::CalendarMonth::DateTool(3pm)
All times are GMT -4. The time now is 02:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy