- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- date comparision + perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2007 09:20 PM
04-22-2007 09:20 PM
date comparision + perl
Please let me know how to compare dates in perl. Let say i have one date as 2/11/2005 2:30AM and other one is 2/11/2005 2:00AM then how i can compare then which is earlier in perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2007 09:39 PM
04-22-2007 09:39 PM
Re: date comparision + perl
please see this perl article:
http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q4.11.html
lots of others if you search a bit
Or you could convert date to epoch and then compare.
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
So far you have awarded points to only ONE of 42 answers !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2007 09:53 PM
04-22-2007 09:53 PM
Re: date comparision + perl
Lots of good date functionality here.
perl
http://hpux.ws/merijn/caljd-2.2.pl
shell
http://hpux.ws/merijn/caljd-2.25.sh
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2007 10:30 PM
04-22-2007 10:30 PM
Re: date comparision + perl
for the epoch version of the solution, please see:
http://www.unix.org.ua/orelly/perl/cookbook/ch03_03.htm
Code and explanation is provided on the link.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2007 12:07 AM
04-23-2007 12:07 AM
Re: date comparision + perl
you merely need to transform your date string
into Unix epoch seconds and compare which of the two is smaller.
The standard Perl module Time::Local does the epoch secs conversion.
The only nasty part is the conversion from string into what timelocal() expects.
Here's one way:
#!/usr/bin/perl
use strict;
use Time::Local;
my @t = ('2/11/2005 2:30AM', '2/11/2005 2:00AM');
printf "%s comes before %s\n", (normalize_date($t[0]) < normalize_date($t[1])) ?
@t : reverse @t;
sub normalize_date {
my ($str) = @_;
my ($date, $time) = split /\s+/, $str;
my ($d, $m, $Y) = split q{/}, $date;
my ($H, $M, $PM) = $time =~ /(\d{1,2}):(\d{1,2})(?:AM|(PM))/i;
$H += 12 if $PM;
timelocal(0, $M, $H, $d, --$m, $Y-1900);
}