- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh TIME stamp compare
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
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
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
тАО01-16-2009 10:31 AM
тАО01-16-2009 10:31 AM
$CURRENT 16-JAN-09-18:27:45
$APPLIED 16-JAN-09-18:24:41
I want to subtract $CURRENT from $APPLIED
All, there may be a case where APPLIED is NULL.
So I need to put an exception in that.
Solved! Go to Solution.
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2009 10:50 AM
тАО01-16-2009 10:50 AM
Re: ksh TIME stamp compare
And I assume that you know how you want to "subtract" these dates :-) ?
You asked how to test if one of the variables is "null". By that, I assume you mean "empty" in the shell context.
# [ -z "${APPLIED}" ] && echo "APPLIED is empty" || echo "APPLIED is set"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2009 10:52 AM
тАО01-16-2009 10:52 AM
Re: ksh TIME stamp compare
This is current: 090116185045
This is applied: 090116183804
Just looking for the arithmetic to find difference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2009 01:57 PM - edited тАО09-04-2011 09:32 PM
тАО01-16-2009 01:57 PM - edited тАО09-04-2011 09:32 PM
Re: ksh TIME stamp compare
>DIFF=$(($CURRENT - $APPLIED))
This will give you a difference with correct ordering but it isn't the normal distance metric for time in seconds. You can find differences but your distance metric is for some 5 dimensional phase space on your time units.
- Tags:
- distance metric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2009 02:14 PM
тАО01-16-2009 02:14 PM
Re: ksh TIME stamp compare
I spoke too soon, I know it was too easy.
I have now changed it to just days & minutes that I am pulling from the oracle database into a file, so the output looks like:
DDMM
But, yikes, now I get into time conversion.
Because if I take:
CURRENT is: 162201
APPLY is: 162108
It comes back with 93 minutes difference.
Which is wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2009 02:18 PM
тАО01-16-2009 02:18 PM
Re: ksh TIME stamp compare
DDHH24MI
Which gives me:
162215
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2009 02:49 PM
тАО01-16-2009 02:49 PM
SolutionPerl can make your task painless.
# cat ./datediff
#!/usr/bin/perl
use strict;
use warnings;
use Date::Calc qw(Delta_DHMS);
my $date1 = shift or die "first YYYYMMDDHHMMSS expected\n";
my $date2 = shift or die "second YYYYMMDDHHMMSS expected\n";
my ( $year1, $month1, $day1, $hour1, $min1, $sec1 )
= unpack( "A4A2A2A2A2A2", $date1 );
my ( $year2, $month2, $day2, $hour2, $min2, $sec2 )
= unpack( "A4A2A2A2A2A2", $date2 );
my ( $Dd, $Dh, $Dm, $Ds ) = Delta_DHMS(
$year1, $month1, $day1, $hour1, $min1, $sec1,
$year2, $month2, $day2, $hour2, $min2, $sec2
);
print "difference is $Dd days $Dh hours $Dm minutes $Ds seconds\n";
1;
...run as:
# ./datediff 20090116185045 20090116183804
difference is 0 days 0 hours -12 minutes -41 seconds
# ./datediff 20090116183804 20090116185045
difference is 0 days 0 hours 12 minutes 41 seconds
That is, pass two date-time strings each in the format YYYMMDDHHMMSS
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-16-2009 02:54 PM
тАО01-16-2009 02:54 PM
Re: ksh TIME stamp compare
But, yikes, now I get into time conversion.
Because if I take:
CURRENT is: 162201
APPLY is: 162108
It comes back with 93 minutes difference.
Which is wrong.
********
When you are just subtracting a number, yes the difference is 93.
The problem is that the shell has absolutely NO CLUE that what you have is a date/time.
Think about it like this:
162,201 - 162,108 = 93.
James' solution above should do what you require.