Operating System - HP-UX
1829108 Members
13354 Online
109986 Solutions
New Discussion

Re: display time described by STRING, not NOW

 
SOLVED
Go to solution
Hakki Aydin Ucar
Honored Contributor

display time described by STRING, not NOW

I am looking for date -d option (like in Linux) in HP-UX but apparently there is not. So, how can I get the days of today OR on any given days, from the current year in shell OR Perl epoch ?

like this in Linux:
# date -d 01/03/2010 +%j
003
# date -d 12/31/2010 +%j
365
8 REPLIES 8
Hakki Aydin Ucar
Honored Contributor

Re: display time described by STRING, not NOW

Day Of The Year is working for current date:
# date +%j
259

but not for a given date period..
James R. Ferguson
Acclaimed Contributor

Re: display time described by STRING, not NOW

Hi:

You can install the 'Date::Calc' module from CPAN and use its 'Day_of_Year' function.

http://search.cpan.org/~stbey/Date-Calc-6.3/lib/Date/Calc.pod

Regards!

...JRF...
Turgay Cavdar
Honored Contributor

Re: display time described by STRING, not NOW

Hakki Aydin Ucar
Honored Contributor

Re: display time described by STRING, not NOW

looking for a local solution due to server is a production machine and cannot put any extra module. I ve to find local workaround,
James R. Ferguson
Acclaimed Contributor
Solution

Re: display time described by STRING, not NOW

Hi (again) Hakki:

Well, rolling your own isn't hard:

# cat /.showday
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
use POSIX qw( strftime );
my ( $mon, $day, $year ) = split m{/}, shift;
my $time = timelocal( 0, 0, 0, $day, $mon - 1, $year );
print strftime( "%j\n", localtime($time) );
1;

...run as:

# ./showday 09/16/2010
259

# ./showday 12/31/2010
365

# ./showday 12/31/2012
366

Regards!

...JRF...
Hakki Aydin Ucar
Honored Contributor

Re: display time described by STRING, not NOW

Hi JRF,
Thaks for great solutions,
the only thing I tried to learn "strftime" is inside a C class header "time.h" ,
I cannot use it directly in command line,but in Perl with POSIX module,
Am I right ??
Dennis Handly
Acclaimed Contributor

Re: display time described by STRING, not NOW

>the only thing I tried to learn strftime(3) is inside a C class header "time.h" ,
>I cannot use it directly in command line but in Perl with POSIX module

When you use "date +" you are using strftime(3) but only with NOW.
If you want use other times, you are left with perl or a language like C or C++.
James R. Ferguson
Acclaimed Contributor

Re: display time described by STRING, not NOW

Hi (again) Hakki:

> the only thing I tried to learn "strftime" is inside a C class header "time.h" ,
I cannot use it directly in command line,but in Perl with POSIX module,
Am I right ??

Yes, you can't use it in a shell script, but Perl's POSIX module provides hooks into the 'libc' library so you have the support I offered. The POSIX module offers access nearly all of the standard POSIX 1003.1 identifiers.

Regards!

...JRF...