Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
Here is the problem:
How do I calculate the time difference in Unix ? For example time difference between 02 AUG 2006 6:20:30 pm and 04 AUG 2006 12:15:45 pm in intended units ie ; min. Any idea is welcome.

This type of problem is best solved by determining the number of seconds from the epoch - Jan 1, 1970 GMT. The common Unix tools doesn't handle this problem very well (although GNU's gawk & date commands do). I'd use a scripting language like Perl:
#!/usr/local/bin/perl
use Time::Local;
# months start at 0
# years have 1900 subtracted:###time=timelocal($sec, $min, $hours, $day, $mon, $year)
$time1=timelocal(30, 20, 18, , 2, 7, 106);
$time2=timelocal(45, 15, 12, , 4, 7, 106);$time3=$time2-$time1;
print "$time3 difference in seconds\n";

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

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