The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
mtime, ctime, and atime Perderabo Tips and Tutorials 2 08-30-2007 06:13 AM
how to find ot ctime , mtime ,atime nilesrex Shell Programming and Scripting 4 08-10-2006 07:51 AM
atime, ctime, mtime somewhere along csize.. moxxx68 UNIX for Dummies Questions & Answers 4 03-02-2005 02:14 PM
mtime vs ctime moxxx68 UNIX for Dummies Questions & Answers 3 11-06-2004 06:57 PM
ctime & find 98_1LE UNIX for Dummies Questions & Answers 1 06-22-2001 12:33 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-21-2002
Registered User
 

Join Date: Aug 2002
Posts: 4
Stumble this Post!
Converting regular time to CTIME

Does anyone know of an easy way to convert regular time 08/21/2002 @ 8:21:21 pm to ctime. I need this to complete a script that I am writing.

Your expertise and help would be amost appreciated. Please note - I am not a programmer so c-code etc will not help. A utility that can be run from a commnd line or an easy script for unix would help a great deal.

Thanks.
Forum Sponsor
  #2 (permalink)  
Old 08-21-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Stumble this Post!
Try looking at the man page for your implementation of the date command.
On a Linux system, you can get (for example) the number of seconds from the epoch like this:
Code:
date +%s
Or if you want the date yesterday in YYYYMMDD format, you can do this:
Code:
date --date="1 day ago" +%Y%m%d
Note: the --date option is specific to GNU date, as far as I know, and is not portable...

If you have any other questions about date handling, please respond, as I have been doing a lot of tedious date juggling in scripts lately.

If you do reply, please include your operating system (available via the uname -a command), and if possible, which "date" you are using. Also, please give examples of which formats you are converting from, and the expected output.
  #3 (permalink)  
Old 08-21-2002
asifraj's Avatar
Registered User
 

Join Date: Aug 2002
Location: India
Posts: 48
Stumble this Post!
boy, if you are using unix or linux,
all you have to do is

man date

and you'll get to know everything you want
  #4 (permalink)  
Old 08-22-2002
Registered User
 

Join Date: Aug 2002
Posts: 4
Stumble this Post!
ctime conversion

I am actually trying to get a script to move our backup tapes from one system to another and the assigned date / time is in the format ... 02/01/2002 10:13:17 AM. To import the tapes there is a parameter for the assigned time but it needs ctime which, in this case is ... 1012587197.

I know of DTConverter but it does not have any command line switches to automatically perform the task within a script.

If I give the initial format a variable named for e.g. ASSIGNED, how can I use that to get another variable name for e.g. CASSIGNED which will have the inital $ASSIGNED converted to ctime?

Hopefully this makes sense.

Thanks kindly for any help that you can give.

BTW - I am running the sctipt on an NT 2000 server using the UNIX Korn Shell utilities.

NIce way to make NT useful, install UNIX commands on it...
  #5 (permalink)  
Old 08-22-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Stumble this Post!
If you can find a port of GNU "date" for Win*, I would personally install that. It should be as easy as that, and it will work it's way into a script very nicely:
Code:
...
ASSIGNED="02/01/2002 10:13:17 AM"
CASSIGNED=$(date --date="$ASSIGNED" +%s)

print $CASSIGNED
...
Would it be possible to install "date"?
  #6 (permalink)  
Old 08-22-2002
Registered User
 

Join Date: Aug 2002
Posts: 4
Stumble this Post!
I must admit ...

As much as I would like to say that I understand exactly what you are saying - I must admit that I am still at a loss.

Although I understand the code and what it is doing - What is "a port of GNU date for WIN"?

I have the UNIX MKS toolkit installed and it has the UNIX date function but the man page does not list the %s variable and the code you gave does not work so I assume that the "port of GNU date for WIN" is what is missing?

Can you possibly enlighten me further as this would be saving me a lot of work?

Thank you for all your help - It is much appreciated.
  #7 (permalink)  
Old 08-22-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Stumble this Post!
Sorry 'bout that...

The GNU project (http://www.gnu.org) has a version of the "date" program that ties some incredible functionality into the "standard" date...

A quick Google search for "GNU date.exe" found this page, among others:
http://www.weihenstephan.de/~syring/win32/UnxUtils.html

I've never used them, so I don't know how well they work, or if they're even the right version I'm looking for...

You might not be able to find GNU date for the Windows platform...
Google The UNIX and Linux Forums
Closed Thread

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:43 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