The UNIX and Linux Forums  

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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 07:23 AM
Get date and time for past 1 hour from current date spch2o Shell Programming and Scripting 4 12-21-2007 05:55 AM
Date/Time help ssmiths001 Shell Programming and Scripting 5 01-26-2006 11:40 PM
date and time ker UNIX for Dummies Questions & Answers 3 11-07-2002 07:47 AM
date/time baileyr1 Shell Programming and Scripting 4 05-16-2002 02:35 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-18-2002
Registered User
 

Join Date: Jul 2002
Posts: 13
Calculte date time

Hi All,
Please help me in solving this. How can I find the date time, given seconds in number from date 01/01/2002. Using K shell
or C program

Example if I have 3600 (seconds) I should get the output as
01/01/2002 1:00:00 am


Thanks in advance
Krishna
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-18-2002
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
You might find your answer using Perderabo's datecalc script found here
Reply With Quote
  #3 (permalink)  
Old 07-18-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,318
datecalc is a start, but it only handles dates, not time. This script should do the trick...

Code:
#! /usr/bin/ksh

        integer inputsecs days daysecond hoursecond
        typeset -Z2 month day hour minute second

        inputsecs=$1

        ((days=inputsecs/86400))
        ((daysecond=inputsecs%86400))
        ((hour=daysecond/3600))
        ((hoursecond=daysecond-(hour*3600)))
        ((minute=hoursecond/60))
        ((second=hoursecond%60))

        datecalc -a 2001 1 1 + $days | read year month day

        if((hour < 12)) ; then
                p="am"
        else 
                ((hour=hour-12))
                p="pm"
        fi
        ((hour == 0)) && ((hour=12))

        time="$month/$day/$year ${hour}:${minute}:${second} $p"
        echo "$time"
exit 0
Reply With Quote
  #4 (permalink)  
Old 07-18-2002
Registered User
 

Join Date: Jul 2002
Posts: 13
Thanks for the code .
Do you have a C program to do this. Code in K Shell looks complicated to me. I do not use much of K Shell. I better use C program

Thanks once again
Krishna
__________________
Sai
Reply With Quote
  #5 (permalink)  
Old 07-18-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,318
Sorry, I don't have this in C.
Reply With Quote
  #6 (permalink)  
Old 08-05-2002
Registered User
 

Join Date: Jul 2002
Posts: 13
Thanks for your help
__________________
Sai
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0