Converting regular time to CTIME


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Converting regular time to CTIME
# 1  
Old 08-21-2002
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.
# 2  
Old 08-21-2002
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  
Old 08-22-2002
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
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.

Smilie NIce way to make NT useful, install UNIX commands on it...
# 5  
Old 08-22-2002
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  
Old 08-22-2002
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  
Old 08-23-2002
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...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting time format as Integer to seconds

Hello, How can we convert date like format 20181004171050 in seconds ? I can able to convert till date but failing for HHMMSS. date -d "20181004" "+%s" output as 1538596800 . But when i add hhmmss it is failing date -d "20181004172000" "+%s" result Invalid date Kindly guide. Regards (16 Replies)
Discussion started by: sadique.manzar
16 Replies

2. Shell Programming and Scripting

Converting seconds to time

I have a list of time spans in seconds, and want to compute the time span as hh:mm:nn I am coding in bash and have coded the following. However, the results are wrong as "%.0f" rounds the values. Example: ftm: 25793.5 tmspan(hrs,min,sec): 7.16 429.89 25793.50 hh: 7 mm: 10 ss:... (2 Replies)
Discussion started by: kristinu
2 Replies

3. Shell Programming and Scripting

Converting a random epoch time into a readable format

I am trying to create a script that will take epoch (input from command line) and convert it into a readable format in bash/shell ---------- Post updated at 08:03 PM ---------- Previous update was at 07:59 PM ---------- #!bin/bash read -p "Please enter a number to represent epoch time:"... (9 Replies)
Discussion started by: sprocket
9 Replies

4. UNIX for Dummies Questions & Answers

Converting Epoch time

I have a Raspberry Pi that logs some temperatures using Onewire. Data is collected with RRDTool. The command sudo rrdtool fetch ute_temp.rrd AVERAGE -s -1h > ./test.log and then cat test.log gives the result 1388608500: 2.3579639836e+00 . How do I write a script that converts the Epoch time... (4 Replies)
Discussion started by: nilekl
4 Replies

5. Shell Programming and Scripting

Converting real time to epoch time

# date +%s -d "Mon Feb 11 02:26:04" 1360567564 # perl -e 'print scalar localtime(1360567564), "\n";' Mon Feb 11 02:26:04 2013 the epoch conversion is working fine. but one of my application needs 13 digit epoch time as input 1359453135154 rather than 10 digit epoch time 1360567564... (3 Replies)
Discussion started by: vivek d r
3 Replies

6. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk. I tried This is how each line of the file looks like, different date and time in this format Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th ... (2 Replies)
Discussion started by: bkkid
2 Replies

7. Shell Programming and Scripting

converting epoch time to ddmmyy format

I can not find a working script or way to do this on sun solaris , can someone please guide me? e.g 1327329935 epoch secs = 012312 (ddmmyy) thanks (5 Replies)
Discussion started by: aliyesami
5 Replies

8. Shell Programming and Scripting

converting epoch time

Hi, Thanks bartus11 yesterday's code worked fine for me. In meantime I've found another "issue". As you can see highlighted, the time format in my original input in case of two rows which should be duplicited ,is differentwhat I need to do is to convert to this format "20110607-08:03:22"... (4 Replies)
Discussion started by: hernand
4 Replies

9. UNIX for Advanced & Expert Users

problem with converting time using perl

Hello, I have an AIX 5.3 system and i created a script to get the last login of users. The script goes like this: LAST_LOGIN=`lsuser -a time_last_login $cur_user` TIME_LOGIN=`perl -e 'print scalar localtime("$LAST_LOGIN")'` Actually what i do in these two lines is to set a variable... (2 Replies)
Discussion started by: omonoiatis9
2 Replies

10. Shell Programming and Scripting

Help converting date-time value to decimal

Hi I need help to do some calculation in script. I have a monitor program (munin) that I would like to log uptime information from a server. The script looks like this (not complete): #!/bin/sh # server_uptime ### Config Start # Reads the server parameters using the HTTP port with... (7 Replies)
Discussion started by: Jotne
7 Replies
Login or Register to Ask a Question