|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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 | ||
|
![]() |
| Tags |
| linux, unix commands |
| Thread Tools | Search this Thread |
| 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 10:49 PM |
| Converting a user inputted date to epoch time | ada | Programming | 2 | 09-20-2011 08:49 PM |
| converting epoch time | hernand | Shell Programming and Scripting | 4 | 06-08-2011 06:59 AM |
| problem with converting time using perl | omonoiatis9 | UNIX for Advanced & Expert Users | 2 | 05-09-2011 10:07 AM |
| Help converting date-time value to decimal | Jotne | Shell Programming and Scripting | 7 | 12-31-2010 09:20 AM |
|
|