Sponsored Content
Top Forums UNIX for Advanced & Expert Users How can i calculate a Quarter of a Month Post 302153732 by shamrock on Wednesday 26th of December 2007 11:47:37 AM
Old 12-26-2007
Code:
mon=$(date +'%m')
if [ $mon -ge 1 -a $mon -le 3 ]; then
     qtr=1
elif [ $mon -ge 4 -a $mon -le 6 ]; then
     qtr=2
elif [ $mon -ge 7 -a $mon -le 9 ]; then
     qtr=3
elif [ $mon -ge 10 -a $mon -le 12 ]; then
     qtr=4
fi
echo $qtr

 

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

calculate the number of days left in a month

does any one have any ideas how i would go about calculating the number of days left in the month from a bash script ?. I want to do some operations on a csv file according to the result (8 Replies)
Discussion started by: dunryc
8 Replies

3. UNIX for Dummies Questions & Answers

code to identify the New Quarter

I am a sql programmer, I don't know much about UNIX. I want to modify the existing unix script ----------------------------------------------------------------- ............ cd /home/location/file set timing on sqlplus user/$IDPW <<! prompt RUNNING NEW QUARTER PROCESSING. PLEASE WAIT.... (1 Reply)
Discussion started by: stefani
1 Replies

4. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

5. UNIX for Dummies Questions & Answers

Get Quarter Date

Hi I need to produce a report that the start date must be the first day of the current quarter. Therefore a repor that is run today the start date would be 01/10/2010 (ddmmyyyy). Obvioulsy I could hard code this date in but what happens when the report is run in January the start of the... (6 Replies)
Discussion started by: theref
6 Replies

6. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

7. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

8. Shell Programming and Scripting

Get 1st date of month, week , quarter

Hi , I need to trigger few jobs based on the system date ( in case user is not passing any date to the script. In case passing then need to take the user date). Here is the requirement 1. Everyday call daily script 2. On 1st day of week call weekly script 3. On 1st day of month call... (4 Replies)
Discussion started by: Anupam_Halder
4 Replies

9. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

10. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies
strptime(3C)						   Standard C Library Functions 					      strptime(3C)

NAME
strptime - date and time conversion SYNOPSIS
#include <time.h> char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tm); Non-zeroing Behavior cc [flag...] file... -D_STRPTIME_DONTZERO [library...] #include <time.h> char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tm); DESCRIPTION
The strptime() function converts the character string pointed to by buf to values which are stored in the tm structure pointed to by tm, using the format specified by format. The format argument is composed of zero or more conversion specifications. Each conversion specification is composed of a "%" (percent) character followed by one or two conversion characters which specify the replacement required. One or more white space characters (as spec- ified by isspace(3C)) may precede or follow a conversion specification. There must be white-space or other non-alphanumeric characters between any two conversion specifications. A non-zeroing version of strptime(), described below under Non-zeroing Behavior, is provided if _STRPTIME_DONTZERO is defined. Conversion Specifications The following conversion specifications are supported: %% Same as %. %a Day of week, using the locale's weekday names; either the abbreviated or full name may be specified. %A Same as %a. %b Month, using the locale's month names; either the abbreviated or full name may be specified. %B Same as %b. %c Locale's appropriate date and time representation. %C Century number (the year divided by 100 and truncated to an integer as a decimal number [1,99]); single digits are preceded by 0. If %C is used without the %y specifier, strptime() assumes the year offset is zero in whichever century is specified. Note the behav- ior of %C in the absence of %y is not specified by any of the standards or specifications described on the standards(5) manual page, so portable applications should not depend on it. This behavior may change in a future release. %d Day of month [1,31]; leading zero is permitted but not required. %D Date as %m/%d/%y. %e Same as %d. %h Same as %b. %H Hour (24-hour clock) [0,23]; leading zero is permitted but not required. %I Hour (12-hour clock) [1,12]; leading zero is permitted but not required. %j Day number of the year [1,366]; leading zeros are permitted but not required. %m Month number [1,12]; leading zero is permitted but not required. %M Minute [0-59]; leading zero is permitted but not required. %n Any white space. %p Locale's equivalent of either a.m. or p.m. %r Appropriate time representation in the 12-hour clock format with %p. %R Time as %H:%M. SUSv3 %S Seconds [0,60]; leading zero is permitted but not required. The range of values is [00,60] rather than [00,59] to allow for the occasional leap second. Default and other standards %S Seconds [0,61]; leading zero is permitted but not required. The range of values is [00,61] rather than [00,59] to allow for the occasional leap second and even more occasional double leap second. %t Any white space. %T Time as %H:%M:%S. %U Week number of the year as a decimal number [0,53], with Sunday as the first day of the week; leading zero is permitted but not required. %w Weekday as a decimal number [0,6], with 0 representing Sunday. %W Week number of the year as a decimal number [0,53], with Monday as the first day of the week; leading zero is permitted but not required. %x Locale's appropriate date representation. %X Locale's appropriate time representation. %y Year within century. When a century is not otherwise specified, values in the range 69-99 refer to years in the twentieth century (1969 to 1999 inclusive); values in the range 00-68 refer to years in the twenty-first century (2000 to 2068 inclusive). %Y Year, including the century (for example, 1993). %Z Time zone name or no characters if no time zone exists. Modified Conversion Specifications Some conversion specifications can be modified by the E and O modifier characters to indicate that an alternate format or specification should be used rather than the one normally used by the unmodified specification. If the alternate format or specification does not exist in the current locale, the behavior will be as if the unmodified conversion specification were used. %Ec Locale's alternate appropriate date and time representation. %EC Name of the base year (era) in the locale's alternate representation. %Ex Locale's alternate date representation. %EX Locale's alternate time representation. %Ey Offset from %EC (year only) in the locale's alternate representation. %EY Full alternate year representation. %Od Day of the month using the locale's alternate numeric symbols. %Oe Same as %Od. %OH Hour (24-hour clock) using the locale's alternate numeric symbols. %OI Hour (12-hour clock) using the locale's alternate numeric symbols. %Om Month using the locale's alternate numeric symbols. %OM Minutes using the locale's alternate numeric symbols. %OS Seconds using the locale's alternate numeric symbols. %OU Week number of the year (Sunday as the first day of the week) using the locale's alternate numeric symbols. %Ow Number of the weekday (Sunday=0) using the locale's alternate numeric symbols. %OW Week number of the year (Monday as the first day of the week) using the locale's alternate numeric symbols. %Oy Year (offset from %C) in the locale's alternate representation and using the locale's alternate numeric symbols. General Specifications A conversion specification that is an ordinary character is executed by scanning the next character from the buffer. If the character scanned from the buffer differs from the one comprising the specification, the specification fails, and the differing and subsequent char- acters remain unscanned. A series of specifications composed of %n, %t, white-space characters or any combination is executed by scanning up to the first character that is not white space (which remains unscanned), or until no more characters can be scanned. White space is defined by isspace(3C). Any other conversion specification is executed by scanning characters until a character matching the next specification is scanned, or until no more characters can be scanned. These characters, except the one matching the next specification, are then compared to the locale values associated with the conversion specifier. If a match is found, values for the appropriate tm structure members are set to values corresponding to the locale information. If no match is found, strptime() fails and no more characters are scanned. The month names, weekday names, era names, and alternate numeric symbols can consist of any combination of upper and lower case letters. The user can request that the input date or time specification be in a specific language by setting the LC_TIME category using setlo- cale(3C). Non-zeroing Behavior In addition to the behavior described above by various standards, the Solaris implementation of strptime() provides the following exten- sions. These may change at any time in the future. Portable applications should not depend on these extended features: o If _STRPTIME_DONTZERO is not defined, the tm struct is zeroed on entry and strptime() updates the fields of the tm struct asso- ciated with the specifiers in the format string. o If _STRPTIME_DONTZERO is defined, strptime() does not zero the tm struct on entry. Additionally, for some specifiers, strp- time() will use some values in the input tm struct to recalculate the date and re-assign the appropriate members of the tm struct. The following describes extended features regardless of whether _STRPTIME_DONTZERO is defined or not defined: o If %j is specified, tm_yday is set; if year is given, and if month and day are not given, strptime() calculates and sets tm_mon, tm_mday, and tm_year. o If %U or %W is specified and if weekday and year are given and month and day of month are not given, strptime() calculates and sets tm_mon, tm_mday, tm_wday, and tm_year. The following describes extended features when _STRPTIME_DONTZERO is not defined: o If %C is specified and %y is not specified, strptime()assumes 0 as the year offset, then calculates the year, and assigns tm_year. The following describes extended features when _STRPTIME_DONTZERO is defined: o If %C is specified and %y is not specified, strptime() assumes the year offset of the year value of the tm_year member of the input tm struct, then calculates the year and assigns tm_year. o If %j is specified and neither %y, %Y, nor %C are specified, and neither month nor day of month are specified, strptime() assumes the year value given by the value of the tm_year field of the input tm struct. Then, in addition to setting tm_yday, strptime() uses day-of-year and year values to calculate the month and day-of-month, and assigns tm_month and tm_mday. o If %U or %W is specified, and if weekday and/or year are not given, and month and day of month are not given, strptime() will assume the weekday value and/or the year value as the value of the tm_wday field and/or tm_year field of the input tm struct. Then, strptime() will calculate the month and day-of-month and assign tm_month, tm_mday, and/or tm_year. o If %p is specified and if hour is not specified, strptime() will reference, and if needed, update the tm_hour member. If the am_pm input is p.m. and the input tm_hour value is between 0 - 11, strptime() will add 12 hours and update tm_hour. If the am_pm input is a.m. and input tm_hour value is between 12 - 23, strptime() will subtract 12 hours and update tm_hour. RETURN VALUES
Upon successful completion, strptime() returns a pointer to the character following the last character parsed. Otherwise, a null pointer is returned. USAGE
Several "same as" formats, and the special processing of white-space characters are provided in order to ease the use of identical format strings for strftime(3C) and strptime(). The strptime() function tries to calculate tm_year, tm_mon, and tm_mday when given incomplete input. This allows the struct tm created by strptime() to be passed to mktime(3C) to produce a time_t value for dates and times that are representable by a time_t. As an example, since mktime() ignores tm_yday, strptime() calculates tm_mon and tm_mday as well as filling in tm_yday when %j is specified without other- wise specifying a month and day within month. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ |Standard |See standards(5). | +-----------------------------+-----------------------------+ SEE ALSO
ctime(3C), getdate(3C), isspace(3C), mktime(3C), setlocale(3C), strftime(3C), attributes(5), environ(5), standards(5) SunOS 5.11 27 Aug 2007 strptime(3C)
All times are GMT -4. The time now is 10:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy