Sponsored Content
Top Forums Shell Programming and Scripting Display previous days dates in ksh Post 302880156 by pr5439 on Wednesday 18th of December 2013 01:34:32 PM
Old 12-18-2013
hi,
Problem is similar so tried continuing in the same thread than opening a new one. the problem now is i am trying to calculate time elapsed between two instances, at present i am using below in awk where date command doesn't work:
Code:
std=substr($2,4,2) ;                          #start date
end=substr($4,4,2) ;                         #end date
mul=((end-std)-1);                           #no: of full days elapsed in the interval
t1=(3600*substr($3,1,2)+60*substr($3,4,2)+substr($3,7,2)); #total no: of start time seconds
t2=(3600*substr($5,1,2)+60*substr($5,4,2)+substr($5,7,2)); #total no: of end time seconds
if (mul == "-1")                                 #both instances in the same day
t=t2-t1;
else                                               #instances occur in two different days
t=((24*3600)-t1)+(mul*24*3600)+t2;
printf("%02d:%02d:%02d\n",(t/3600),((t/60)%60),t%60);      #time elapsed in HH:MM:YY format

my input file will be like
name1 12/16/2013 10:56:38 12/16/2013 10:59:37 value1
name2 12/16/2013 04:37:41 12/17/2013 11:34:19 value2

and so on(a sequence of such records)

the problem again is the same. If start of the month appears with date 01 the previous day would be 31 or 30 or 28 (or 29 ) and my logic above wont work then.
One way is i hard code such inatances with month values in case statement. But just want to know if there is some better option to deal this ?
Any help will be gratefully welcome :-)

---------- Post updated 12-18-13 at 01:34 PM ---------- Previous update was 12-17-13 at 05:40 PM ----------

Does any one have any update? Atleast someone reply that there is no other way to do. Please make a reply so that I try some approach of mine.

Last edited by pr5439; 12-17-2013 at 06:57 PM.. Reason: more explaination
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

days elapsed between 2 dates

does anybody know how to find out the number of days elapsed between 2 dates e.g. days elapsed between 020212 and 020110 (YYMMDD format) Thanking you in advance. Ravi. (1 Reply)
Discussion started by: rkkiran
1 Replies

2. Shell Programming and Scripting

Difference between two dates in no of days ???

Hi All How to get the difference between two dates in no of days ??? My date format is like this YYYY/MM/DD. I have to get the no of days between two dates in the given format. I tried to search the forum but nothing came up similar to my requitement. Your help will be appreciated. ... (1 Reply)
Discussion started by: csaha
1 Replies

3. UNIX for Dummies Questions & Answers

Dates of previous years

Is there any way to use date with previous dates such as "2 23 2000" in order to see what day of the week it was? I tried changing the current date to "date 022300452000" but then it told me that I could not do this because I was "Not the owner". Any other ways of getting the day result? (2 Replies)
Discussion started by: terms5
2 Replies

4. Shell Programming and Scripting

Days difference between two dates

Hello, I would like to find out the number of days between two dates of the format yyyy-mm-dd. Any help on this is highly appreciated. Thanks. (6 Replies)
Discussion started by: Data469
6 Replies

5. UNIX for Dummies Questions & Answers

using 'date' to get previous days' dates

I am familiar with using the 'date' command to get the current date but I have a situation where I need to get the previous day's date as well as the date two days prior. Theoretically I could use 'expr' to compute these values but I need it to work in instances where the previous month's dates... (2 Replies)
Discussion started by: slant-40
2 Replies

6. UNIX for Dummies Questions & Answers

display all dates 200 days back

i need help! can someone help me please? i try to calculate date under unix (ksh)...AIX operating system. I have to find the date 200 days from today's date. then the script should loop 200 times and display on command line every day's date until the current date. example: todays date:... (1 Reply)
Discussion started by: pavan_test
1 Replies

7. Shell Programming and Scripting

display all dates 200 days back

i need help! can someone help me please? i try to calculate date under unix (ksh)...AIX operating system. I have to find the date 200 days from today's date. then the script should loop 200 times and display on command line every day's date until the current date. example: todays date:... (4 Replies)
Discussion started by: pavan_test
4 Replies

8. Shell Programming and Scripting

days are between the two dates?

I have two times in the format of YYMMDD. Does anyone know an easy way in ksh for me to display how many days are between the two dates? Example1: X=101202 Y=101205 There are 3 days between X & Y Example2: X=101202 Y=111202 There are 365 days between X & Y Example3: X=101205... (3 Replies)
Discussion started by: oldman2
3 Replies

9. Shell Programming and Scripting

Difference in dates in days (ksh shell)

Hi Guys, Need a small help, how do i get the difference between two dates (in days) in KSH shell My date is in mm/dd/YYYY format, Is there a function to get time stamp from the respective date and time ( mm/dd/yyyy HH:MM:SS) (1 Reply)
Discussion started by: selvankj
1 Replies

10. Shell Programming and Scripting

Get number of days between 2 dates

Gents. Please can u help. I would like to calculate the days between two dates. Example file1 ( previous date) file1 - Input file 9/29/2010 10195 9/29/2010 1057 2/2/2016 10 2/2/2016 10169 2/2/2016 1057 2/3/2016 10005 2/3/2016 10014 In file2 I add the actual date using this code.... (9 Replies)
Discussion started by: jiam912
9 Replies
suspend(1)                                                         User Commands                                                        suspend(1)

NAME
suspend - shell built-in function to halt the current shell SYNOPSIS
sh suspend csh suspend ksh suspend DESCRIPTION
sh Stops the execution of the current shell (but not if it is the login shell). csh Stop the shell in its tracks, much as if it had been sent a stop signal with ^Z. This is most often used to stop shells started by su. ksh Stops the execution of the current shell (but not if it is the login shell). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), kill(1), ksh(1), sh(1), su(1M), attributes(5) SunOS 5.10 15 Apr 1994 suspend(1)
All times are GMT -4. The time now is 10:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy