Computing.Net > Forums > Solaris > date diffrence in solaris no %s

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

date diffrence in solaris no %s

Reply to Message Icon

Name: abhargav
Date: April 20, 2005 at 19:27:10 Pacific
OS: solaris
CPU/Ram: 256
Comment:

hi i hav the two time stamps in the form of
Mar 27 2005 05:48:02
Apr 2 2005 15:31:17
now i want to find the diffrence of timestamps in solaris.but i m unable to do so.In slackware i can find out the date diffrence using this,

echo $(( $(date -d 'Apr 2 2005 15:31:17' '+%s') - $(date -d 'Mar 27 2005 05:48:02' '+%s') ))

but how do i find the date diffrence in solaris.As i man pages solaris,it says that -d and %s are not included in solaris.
plz reply as soon as possible.
got my project due
thanx

hi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messages

Mar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:

no



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: April 21, 2005 at 03:49:59 Pacific
Reply:

Have a look at the thread

http://www.computing.net/unix/wwwboard/forum/5648.html

Let Mr Robertson know what fine work he has there.


0

Response Number 2
Name: David Perry
Date: April 22, 2005 at 04:39:48 Pacific
Reply:

In general, time calculations in the shell are difficult. Consider using perl for date and time calculations for an OS independent answer.

==========================
#!/usr/bin/perl -w
use strict;
use Time::ParseDate;

#Read 2 date strings from stdin
print "Enter earliest date: ";
my $date1=<STDIN>;
print "Enter latest date: ";
my $date2=<STDIN>;
chomp $date1; chomp $date2;

#Convert to seconds since start of epoch
my $time1 = parsedate($date1);
my $time2 = parsedate($date2);

#Compute days difference
my $tdiff = $time2 - $time1;
my $ddiff = $tdiff/60/60/24;
print "Difference is $ddiff days\n";
========================

# ./date.pl
Enter earliest date: Mar 27 2005 05:48:02
Enter latest date: Apr 2 2005 15:31:17
Difference is 6.40503472222222 days


0

Response Number 3
Name: abhargav
Date: April 22, 2005 at 07:16:10 Pacific
Reply:

thanx a lot david for quick reply.sorry for mailing you.Before posting on this forum.i was
thinking of using perl and had my script but then as told by my specifications.that it may be possible that perl is not installed as package.is there any way i can use date command or may be i can use awk for finding out the diffrence,is there any way.could you suggest me something,
abhishek

hi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messages

Mar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:

no


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Solaris Forum Home


Sponsored links

Ads by Google


Results for: date diffrence in solaris no %s

BT Voyager in Solaris 10 www.computing.net/answers/solaris/bt-voyager-in-solaris-10/4483.html

Date Problem in Solaris 8 www.computing.net/answers/solaris/date-problem-in-solaris-8/1330.html

Intel EE Pro 100 in Solaris 10 www.computing.net/answers/solaris/intel-ee-pro-100-in-solaris-10/3769.html