Sponsored Content
Full Discussion: calculate 13 months ago
Top Forums Shell Programming and Scripting calculate 13 months ago Post 302146042 by Perderabo on Friday 16th of November 2007 10:34:02 AM
Old 11-16-2007
Code:
$ cat 13months_ago
#! /usr/bin/ksh

for input in 20071115 20071105 20070105 ; do

        year=${input%????}
        day=${input#??????}
        month=${input#????}
        month=${month%??}
        month=${month#0}
        day=${day#0}
        print -n $input $year $month $day

        ((year=year-1))
        ((month=month-1))
        if ((!month)) ; then
                ((year=year-1))
                month=12
        fi
        typeset -Z2 newday newmonth
        newday=$day
        newmonth=$month
        output=${year}${newmonth}${newday}
        print -- " -->" $year $month $day $output
done
exit 0
$ ./13months_ago
20071115 2007 11 15 --> 2006 10 15 20061015
20071105 2007 11 5 --> 2006 10 5 20061005
20070105 2007 1 5 --> 2005 12 5 20051205
$

 

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

deleting files with dates 3 months ago

please help me with this????? :confused: :confused: i need to create a program that will run in unix that will delete all files in a given directory that is at least 3 months old. first the program will need to automatically know what date it is right now to determine the files it will... (3 Replies)
Discussion started by: godalle
3 Replies

2. Shell Programming and Scripting

Cron to run first day of month to calculate date 3 months ago

Hi, I would like to find out how can i calculate a date which is 3 months ago. I intend to run a cron job on the 1st of every month, and calculate the month 4 months earlier from the date. For example, if today's date is 1st May 2007, i would like to return 012007( January 2007). i can get... (1 Reply)
Discussion started by: new2ss
1 Replies

3. Shell Programming and Scripting

calculate 13 months ago

hi, I have a big file that contains datas since 4 years ago. I need re-create this file but just lines that are 13 months ago from today. see what I have: ( I have a file.ksh that calls this file.scl ok !!) ======== file.scl ================ /STATISTICS=stderr /STABLE /NODUPLICATES... (4 Replies)
Discussion started by: andrea_mussap
4 Replies

4. Shell Programming and Scripting

how to calculate the time 10 mins ago?? unix

Hi guys, Im trying to subtract time in ksh script. i.e. basically im querying a database and i want to get the time 10mins before hand..(from) in ksh CurrMin=$(date "+%M") from=`expr $CurrMin - 10` to=$CurrMin however if i run this i say at 2 or 3 mins past the hour, i.e.... (7 Replies)
Discussion started by: k00061804
7 Replies

5. Shell Programming and Scripting

How to calculate months and display in shell scripting

I just want to know, how do we calculate the months in shell scripting. If i give the input as 20-01-2011, the output should be 20-02-2011, 20-03-2011 or 20-04-2011........ How do i get this ? Cheers. (6 Replies)
Discussion started by: sachin24
6 Replies

6. 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
PARSEDATE(3)						   BSD Library Functions Manual 					      PARSEDATE(3)

NAME
parsedate -- date parsing function LIBRARY
System Utilities Library (libutil, -lutil) SYNOPSIS
#include <util.h> time_t parsedate(const char *datestr, const time_t *time, const int *tzoff); DESCRIPTION
The parsedate() function parses a datetime from datestr described in english relative to an optional time point and an optional timezone off- set in seconds specified in tzoff. If either time or tzoff are NULL, then the current time and timezone offset are used. The datestr is a sequence of white-space separated items. The white-space is optional the concatenated items are not ambiguous. An empty datestr is equivalent to midnight today (the beginning of this day). The following words have the indicated numeric meanings: last = -1, this = 0, first, next, or one = 1, second is unused so that it is not confused with ``seconds'', two = 2, third or three = 3, fourth or four = 4, fifth or five = 5, sixth or six = 6, seventh or seven = 7, eighth or eight = 8, ninth or nine = 9, tenth or ten = 10, eleventh or eleven = 11, twelfth or twoelve = 12. The following words are recognized in English only: AM, PM, a.m., p.m. The months: january, february, march, april, may, june, july, august, september, sept, october, november, december, The days of the week: sunday, monday, tuesday, tues, wednesday, wednes, thursday, thur, thurs, friday, saturday. Time units: year, month, fortnight, week, day, hour, minute, min, second, sec, tomorrow, yesterday. Timezone names: gmt, ut, utc, wet, bst, wat, at, ast, adt, est, edt, cst, cdt, mst, mdt, pst, pdt, yst, ydt, hst, hdt, cat, ahst, nt, idlw, cet, met, mewt, mest, swt, sst, fwt, fst, eet, bt, zp4, zp5, zp6, wast, wadt, cct, jst, east, eadt, gst, nzt, nzst, nzdt, idle. A variety of unambiguous dates are recognized: 69-09-10 For years between 69-99 we assume 1900+ and for years between 0-68 we assume 2000+. 2006-11-17 An ISO-8601 date. 10/1/2000 October 10, 2000; the common US format. 20 Jun 1994 23jun2001 1-sep-06 Other common abbreviations. 1/11 the year can be omitted As well as times: 10:01 10:12pm 12:11:01.000012 12:21-0500 Relative items are also supported: -1 month last friday one week ago this thursday next sunday +2 years Seconds since epoch (also known as UNIX time) are also supported: @735275209 Tue Apr 20 03:06:49 UTC 1993 RETURN VALUES
parsedate() returns the number of seconds passed since the Epoch, or -1 if the date could not be parsed properly. SEE ALSO
date(1), eeprom(8) HISTORY
The parser used in parsedate() was originally written by Steven M. Bellovin while at the University of North Carolina at Chapel Hill. It was later tweaked by a couple of people on Usenet. Completely overhauled by Rich $alz and Jim Berets in August, 1990. The parsedate() function first appeared in NetBSD 4.0. BUGS
1 The parsedate() function is not re-entrant or thread-safe. 2 The parsedate() function cannot compute days before the unix epoch (19700101). 3 The parsedate() function assumes years less than 0 mean - year, years less than 70 mean 2000 + year, years less than 100 mean 1900 + year. BSD
December 20, 2010 BSD
All times are GMT -4. The time now is 04:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy