The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pc 0.3-2008-04-02 (Default branch) iBot Software Releases - RSS News 0 04-02-2008 11:40 PM
Rudix 2008 iBot UNIX and Linux RSS News 0 03-25-2008 02:20 AM
Project Management Software - Copper 2008 2008 (Corporate branch) iBot Software Releases - RSS News 0 03-12-2008 07:00 PM
The Top Ten Cybersecurity Threats for 2008 iBot Complex Event Processing RSS News 0 01-05-2008 01:40 PM
Welcome to 2008! Want to know what you?ve gotten into? iBot Complex Event Processing RSS News 0 01-03-2008 11:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-26-2008
Sreejith_VK
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
subtracting Tue, Feb 26, 2008 01:38:25 AM from Mon, Feb 25, 2008 09:30:03 PM

Hi,

Please help me out in creating a script which will subtract Tue, Feb 26, 2008 01:38:25 AM from Mon, Feb 25, 2008 09:30:03 PM and will give me out put in the format hh:mm:ss.

I tried datecalc.It doesnt work for this format.
  #2 (permalink)  
Old 02-26-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
Code:
$ cat datediff.sh
#!/bin/sh

D1=`date +%s -d "Feb 26, 2008 01:38:25 AM"`
D2=`date +%s -d "Feb 25, 2008 09:30:03 PM"`
((diff_sec=D1-D2))
echo - | awk '{printf "%d:%d:%d","'"$diff_sec"'"/(60*60),"'"$diff_sec"'"%(60*60)/60,"'"$diff_sec"'"%60}'

$ sh datediff.sh
4:8:22
//Jadu
  #3 (permalink)  
Old 02-27-2008
Sreejith_VK
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
The script is giving the error:

Quote:
date: bad format character - s
date: bad format character - s
./datediff.sh[5]: diff_sec=D1-D2: bad number
please help!!
  #4 (permalink)  
Old 02-27-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
I thought you said the problem was solved. See Time Between Dates - The UNIX Forums

Please do not open multiple threads for the same problem. You already have opened 3 other threads. Break the rule once more and you will earn a temporary ban.
  #5 (permalink)  
Old 02-27-2008
Sreejith_VK
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
The problem is not yet solved.
The output I require is in hh:mm:ss and dateclac doesn't provide me.
  #6 (permalink)  
Old 02-27-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
First check whether you can see the epoch time for the below command:

Code:
$ date +%s -d "Feb 26, 2008 01:38:25 AM"
1203970105
And if that is successful, then

try

Code:
diff_sec=`expr $D1 - $D2`
instead of

Code:
((diff_sec=D1-D2))
For me the script I gave above works.
  #7 (permalink)  
Old 02-27-2008
manikantants manikantants is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 131
Quote:
Originally Posted by Sreejith_VK View Post
I tried datecalc.It doesnt work for this format.
Convert your date to the required format which datecalc expects and pass it.
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0