Need to convert an epoch date to MMDDYYHHmm format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to convert an epoch date to MMDDYYHHmm format
# 1  
Old 07-08-2010
MySQL Need to convert an epoch date to MMDDYYHHmm format

System: HP-UX
Kornshell
Perl is installed, but not POSIX

Hello,

I am calculating a future date/time. To do this I take the system date in epoch format and add to it. I now need to take the new epoch date and convert it to MMDDYYHHmm format.

Any help with this is greatly appreciated.
# 2  
Old 07-08-2010
One way (adapted from a similar post about dates in the past).


Calculate date 28 days in the future and display in MMDDYYhhmm format, compensating for Perl numbering months from zero and years from 1900.

Code:
perl -w  -e '$d=28*86400;@t=localtime (time +$d); printf "%.2d%.2d%.2d%.2d%.2d", $t[4] +1,$t[3],$t[5] -100,$t[2],$t[1];'


BTW. HP-UX default shell has been Posix for over 10 years. See "man sh".
# 3  
Old 07-08-2010
I am not experiencing the problem with Perl numbering the months correctly. I need to find the date and time 10 minutes ahead, so I just modified the code you posted to:
Code:
perl -w  -e '@t=localtime (time +600); printf "%.2d%.2d%.2d%.2d%.2d", $t[4] +1,$t[3],$t[5] -100,$t[2],$t[1];'

At the time of 13:21, I received output of 0708101331

This appears to be correct . Do you see any potential problems doing it this way?

Good catch on POSIX. What I meant to say was that strftime for awk was not installed. strftime was used in another possible solution I found. Sorry for the confusion.
# 4  
Old 07-08-2010
No issues I can see.

Code:
Note: The code fragment within the "printf"
$t[4] +1
is adding one to the Month to compensate for Perl's month numbering.

This User Gave Thanks to methyl For This Post:
# 5  
Old 07-08-2010
Ok, I understand. Thanks for your help methyl.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert a future date into epoch seconds on HPUX system

Hi All, I have scenario where i have to compare two dates. I thought of converting them to epoch seconds and do a numeric comparison. This works fine on Linux systems. $ date -d '2015/12/31' +%s 1451538000 $ date +%s 1449159121 But we don't have -d option in HPUX. What would be... (5 Replies)
Discussion started by: veeresh_15
5 Replies

2. Shell Programming and Scripting

Convert a date stored in a variable to epoch date

I am not able to pass date stored in a variable as an argument to date command. I get current date value for from_date and to_date #!/usr/bin/ksh set -x for s in server ; do ssh -T $s <<-EOF from_date="12-Jan-2015 12:02:09" to_date="24-Jan-2015 13:02:09" echo \$from_date echo... (7 Replies)
Discussion started by: raj48
7 Replies

3. Shell Programming and Scripting

Convert epoch time stamp into human readable format

Can someone help me to write a shell script to convert epoch timestamp into human readable format 1394553600,"test","79799776.0","19073982.728571","77547576.0","18835699.285714" 1394553600,"test1","80156064.0","19191275.014286","62475360.000000","14200554.720000"... (10 Replies)
Discussion started by: Moon1234
10 Replies

4. Shell Programming and Scripting

Convert epoch time to Julian date

Need assistance in converting an epoch time to Julian date To get epoch perl -e 'use Time::Local; print timelocal(1,5,2,12,10,2008), "\n"' (3 Replies)
Discussion started by: ajayram_arya
3 Replies

5. Shell Programming and Scripting

Using awk or nawk to convert epoch time to date format

Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do. What am I trying to do? I need to take the time value in epoch format returned from the... (5 Replies)
Discussion started by: minigts
5 Replies

6. Shell Programming and Scripting

Convert epoch to human readable date & time format

Hello I have log file from solaris system which has date field converted by Java application using System.currentTimeMillis() function, example is 1280943608380 which equivalent to GMT: Wed, 04 Aug 2010 17:40:08 GMT. Now I need a function in shell script which will convert 1280943608380... (3 Replies)
Discussion started by: Yaminib
3 Replies

7. Shell Programming and Scripting

Convert date into epoch in Perl on Solaris

Solaris 10 doesn't seem to like me a lot. I am trying to run a simple script to accept date and return epoch of that date: #!/usr/bin/perl -w use strict; use Time::ParseDate; my($date1)="Mon Mar 27 05:54:08 CDT 2009"; chomp $date1; #Convert to seconds since start of epoch my $time1 =... (3 Replies)
Discussion started by: pavanlimo
3 Replies

8. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

9. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

10. Shell Programming and Scripting

how to convert epoch time to readible format?

Hi, I would like to convert epoch time from the logs to readible fromat. How do I do it within shell? Thanks! (11 Replies)
Discussion started by: cin2000
11 Replies
Login or Register to Ask a Question