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 an alternate method to convert any given date to epoch seconds on HPUX systems?

Thanks in advance for your help!

Regards,
Veeresham

Can you install the GNU utilities
HP-UX Porting and Archiving Centre | coreutils-8.22

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

You should be able to find something here
http://www.unix.com/answers-to-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

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

#!/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

1 Like

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

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~> _