Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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
thanxhi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messagesMar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:no

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.

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

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,
abhishekhi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messagesMar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:no

![]() |
![]() |
![]() |

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