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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Get date and time for past 1 hour from current date spch2o Shell Programming and Scripting 5 08-29-2008 05:32 AM
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 11:23 AM
Date/Time help ssmiths001 Shell Programming and Scripting 5 01-27-2006 03:40 AM
date and time ker UNIX for Dummies Questions & Answers 3 11-07-2002 11:47 AM
date/time baileyr1 Shell Programming and Scripting 4 05-16-2002 06:35 PM

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 07-18-2002
krishnasai krishnasai is offline
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
  #2 (permalink)  
Old 07-18-2002
RTM's Avatar
RTM RTM is offline Forum Advisor  
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
  #3 (permalink)  
Old 07-18-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
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

  #4 (permalink)  
Old 07-18-2002
krishnasai krishnasai is offline
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
  #5 (permalink)  
Old 07-18-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
Sorry, I don't have this in C.
  #6 (permalink)  
Old 08-05-2002
krishnasai krishnasai is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 13
Thanks for your help
Closed Thread

Bookmarks

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 03:20 PM.


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