Converting regular time to CTIME | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

Converting regular time to CTIME

UNIX for Dummies Questions & Answers


Tags
linux, unix commands

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-21-2002
PGPhantom PGPhantom is offline
Registered User
 
Join Date: Aug 2002
Last Activity: 1 October 2002, 7:21 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #2  
Old 08-21-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
 
Join Date: Jul 2001
Last Activity: 16 June 2011, 4:50 PM EDT
Location: Portland, OR, USA
Posts: 1,626
Thanks: 2
Thanked 15 Times in 13 Posts
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.
Sponsored Links
    #3  
Old 08-22-2002
asifraj's Avatar
asifraj asifraj is offline
Registered User
 
Join Date: Aug 2002
Last Activity: 17 October 2003, 10:33 PM EDT
Location: India
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 08-22-2002
PGPhantom PGPhantom is offline
Registered User
 
Join Date: Aug 2002
Last Activity: 1 October 2002, 7:21 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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...
Sponsored Links
    #5  
Old 08-22-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
 
Join Date: Jul 2001
Last Activity: 16 June 2011, 4:50 PM EDT
Location: Portland, OR, USA
Posts: 1,626
Thanks: 2
Thanked 15 Times in 13 Posts
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"?
Sponsored Links
    #6  
Old 08-22-2002
PGPhantom PGPhantom is offline
Registered User
 
Join Date: Aug 2002
Last Activity: 1 October 2002, 7:21 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
    #7  
Old 08-23-2002
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
 
Join Date: Jul 2001
Last Activity: 16 June 2011, 4:50 PM EDT
Location: Portland, OR, USA
Posts: 1,626
Thanks: 2
Thanked 15 Times in 13 Posts
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...
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
converting epoch time to ddmmyy format aliyesami Shell Programming and Scripting 5 01-24-2012 11:49 PM
Converting a user inputted date to epoch time ada Programming 2 09-20-2011 09:49 PM
converting epoch time hernand Shell Programming and Scripting 4 06-08-2011 07:59 AM
problem with converting time using perl omonoiatis9 UNIX for Advanced & Expert Users 2 05-09-2011 11:07 AM
Help converting date-time value to decimal Jotne Shell Programming and Scripting 7 12-31-2010 10:20 AM



All times are GMT -4. The time now is 05:37 PM.