Converting time format as Integer to seconds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting time format as Integer to seconds
# 8  
Old 10-07-2018
Yes, of course - if you answer my question.
This User Gave Thanks to RudiC For This Post:
# 9  
Old 10-07-2018
Dear RudiC,

It is taking from database and then storing in a file like Integer format.
its like date and time are concatenating and then pushing into flatfiles.

Regards,
# 10  
Old 10-07-2018
Try - if your shell provides "process substitution" -

Code:
date -f<(sed -r 's/([0-9]{8})([0-9]{2})([0-9]{2})([0-9]{2})/\1 \2:\3:\4/' file)  "+%s"
1538666471
1538666473
1538666473
.
.
.

or
Code:
sed -r 's/([0-9]{8})([0-9]{2})([0-9]{2})([0-9]{2})/\1 \2:\3:\4/' file | date -f- "+%s"

This User Gave Thanks to RudiC For This Post:
# 11  
Old 10-07-2018
Thanks RudiC,

One more help please, how can we set the above command for the value instead of file like 20181007130640

Regards,
# 12  
Old 10-07-2018
I don't understand. Please rephrase.
# 13  
Old 10-07-2018
Code:
 sed -r 's/([0-9]{8})([0-9]{2})([0-9]{2})([0-9]{2})/\1 \2:\3:\4/' file | date -f- "+%s"

like for
Code:
sed -r 's/([0-9]{8})([0-9]{2})([0-9]{2})([0-9]{2})/\1 \2:\3:\4/' 20181007130940 | date -f- "+%s"

# 14  
Old 10-07-2018
Kindly tell us what operating system and shell you're using. (Which, as you know, you should tell us every time you start a thread in the Shell Programming and Scripting forum.)

With a POSIX conforming shell, you can easily use various variable expansions to get parts of a string and assignment to assign the reformatted data into another variable. With a csh derived shell, your options might be more limited.

With awk, you can easily use substr() and print or printf or sprintf (depending on what you want to do after that).

What have you tried to solve this problem on your own?
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting seconds to minutes

Hello everyone, I calculate in my bash script the different between two timestamps in seconds. The next step would be to get the difference in minutes, and there is my Problem:AnzahlUeberstunden=$(( $(date -d "$JAHR-$MONAT-$TAG $ArbeitEnde" +%s) - $(date -d "$JAHR-$MONAT-$TAG... (6 Replies)
Discussion started by: Chaos_Lord
6 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. Shell Programming and Scripting

Converting Month into Integer

okay so i run an openssl command to get the date of an expired script. Doing so gives me this: enddate=Jun 26 23:59:59 2012 GMT Then i cut everything out and just leave the month which is "Jun" Now the next part of my script is to tell the user if the the certificate is expired or not... (6 Replies)
Discussion started by: shade917
6 Replies

5. 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

6. Shell Programming and Scripting

Converting decimal to integer

The shell mentioned below will show a warning if the page takes more than 6 seconds to load. The problem is that myduration variable is not an integer. How do I convert it to integer? myduration=$(curl http://192.168.50.1/mantisbt/view.php?id=1 -w %{time_total}) > /dev/null ; ] && echo... (3 Replies)
Discussion started by: shantanuo
3 Replies

7. Shell Programming and Scripting

Converting past date to seconds

Need a little help developing a ksh script. Have read through Perderabo's datecalc routine and it does not seem to fit the function I am looking for. Basically what I am trying to do is find any file (in a specific directory) that was created within the last five minutes. I am not a programming... (3 Replies)
Discussion started by: synergy_texas
3 Replies

8. UNIX for Advanced & Expert Users

converting openssl hex dump or PEM format to integer array

Hello. I'm working on a project that involves creating public/private keys server-side using openssl and using the public key in a Javascript application to encrypt sensitive data in form fields before transmission to the server. Using an SSL https server connection was not an option in this... (1 Reply)
Discussion started by: jhopper
1 Replies

9. Shell Programming and Scripting

Converting integer to String

Hi everyone, I would like to know how to convert an integer to a string. for instance if i=1 i would like to creat a variable called constant1. i want to do this in a for loop so for each value of i, i create a new variable such as constant2, constant3,... and so on. for i in 1 2 3 do ... (1 Reply)
Discussion started by: ROOZ
1 Replies

10. Shell Programming and Scripting

Converting a decimal into integer

Hi all, I'm trying to convert a decimal number into an integer number; I'm doing this: n=`echo |awk '{ print "'"$mem"'"*10}'` where the variable mem is equal to 3.7 I'd like to obtain 37, but the expression above gives me 30. Help please!!!! thx a lot (4 Replies)
Discussion started by: idro
4 Replies
Login or Register to Ask a Question