Convert a future date into epoch seconds on HPUX system


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert a future date into epoch seconds on HPUX system
# 1  
Old 12-03-2015
Oracle 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.

Code:
$ date -d '2015/12/31' +%s
1451538000
$ date +%s
1449159121

But we don't have -d option in HPUX.

What would be an alternate method to convert any given date to epoch seconds on HPUX systems?

Thanks in advance for your help!

Regards,
Veeresham
# 2  
Old 12-03-2015
Can you install the GNU utilities
HP-UX Porting and Archiving Centre | coreutils-8.22
# 3  
Old 12-03-2015
Hi jgt,
I don't have control over installing any package on the servers.
I am looking for some other alternative.May be some perl one liner kind of solution

Regards,
Veeresham
# 4  
Old 12-03-2015
You should be able to find something here
https://www.unix.com/answers-to-frequ...rithmetic.html
# 5  
Old 12-03-2015
Quote:
Originally Posted by veeresh_15
Hi jgt,
I don't have control over installing any package on the servers.
I am looking for some other alternative.May be some perl one liner kind of solution

Regards,
Veeresham
Specific for the format example that you shown, i.e. YYYY/MM/DD

Code:
#!/usr/bin/perl

use strict;
use warnings;
use Time::Local;

my $date = shift || die;

my ($year, $month, $day) = split('/', $date);
$year = ($year<100 ? ($year<70 ? 2000+$year : 1900+$year) : $year);
print timelocal(0, 0, 0, $day, $month-1, $year), "\n";

Run as: perl epoch_time.pl 2015/12/31
This User Gave Thanks to Aia For This Post:
# 6  
Old 12-03-2015
You could try this assuming you have the -j option:-
OSX 10.7.5, default bash terminal...

date -j 'mmddHHMMccyy.ss' +%s

This gives up to the last second before the _New_Year_.
Code:
Last login: Thu Dec  3 22:06:55 on ttys000
AMIGA:barrywalker~> date -j '123123592015.59' +%s
1451606399
AMIGA:barrywalker~> date -r 1451606399
Thu 31 Dec 2015 23:59:59 GMT
AMIGA:barrywalker~> _

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Second Column Date Into EPOCH Time And Print Complete Row

Hello Team, I am stuck in getting the required output in the following case. Please help. My input file is aa|08/01/2016 bb|08/15/2016 I wish to convert the file into aa|epoch time bb|epoch time I am using following code: (3 Replies)
Discussion started by: angshuman
3 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. UNIX for Dummies Questions & Answers

Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)

Below is the sample logfile: Userids Date Time acb Checkout time: 2013-11-20 17:00 axy Checkout time: 2013-11-22 12:00 der Checkout time: 2013-11-17 17:00 xyz Checkout time: 2013-11-19 16:00 ddd Checkout time: 2013-11-21 16:00 aaa Checkout... (9 Replies)
Discussion started by: asjaiswal
9 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

How to convert string(variable) into date( epoch) in ksh on HPUX machine?

Hi all, I have used a bash script which ultimately converts a string into date using date --date option: DATE=$DATE" "$TIME" "`date +%Y` //concatenating 2 strings TMRW_DATE=`date --date="$DATE" +"%s"` //applying date command on string and getting the unixtime Please use code tags... (7 Replies)
Discussion started by: Rashu123
7 Replies

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

7. Shell Programming and Scripting

Date conversion from Standard/given format to seconds/epoch

I am trying get time difference of two dates in secs. Initially I want to convert a standard date format to epoch for two dates and then subtract the two epoch dates. Example : date -d "2007-09-01 17:30:40" '+%s' But this gives me below error date: illegal option -- d Usage: date OS: AIX... (6 Replies)
Discussion started by: bpaac
6 Replies

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

9. Shell Programming and Scripting

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. (4 Replies)
Discussion started by: LetsGoPens
4 Replies

10. 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
Login or Register to Ask a Question