britney has asked for the wisdom of the Perl Monks concerning the following question:
sub get_date { # -------------------------------------------------------- # Returns the date in the format "Mmmm dd, yyyy hh:mm ". # Warning: If you change the default format, you must also modif +y the &date_to_unix # subroutine below which converts your date format into a unix t +ime in seconds for sorting # purposes. my ($time) = @_; ($time) || ($time = time()); my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $day +light) = localtime($time); ($day < 10) and ($day = "0$day"); $mon += 1; ($mon < 10) and ($mon = "0$mon"); $year = $year + 1900; if ($min < 10) { $min = "0" . $min; } return "$mon\/$day\/$year $hour:$min:$sec"; } sub date_to_unix { my ($date) = @_[0]; my ($time); my ($mon, $day, $year) = split(/\//, $_[0]); my ($hour, $min, $sec) = split(/:/, $_[0]); unless ($day and $mon and $year) { return undef; } use Time::Local; eval { $mon = int($mon) - 1; $ +day = int($day); $year = int($year) - 1900; $time = timelocal($sec,$mi +n,$hours,$day,$mon,$year); }; if ($@) { return undef; } # + Could return 0 if you want. return ($time); }
I am using flat file database: SN|Startdate|Completedate|Status 1234ABC|09/23/2003 14:30|09/30/2003 10:00|CompletedIf I want to check for the running time I should change starttime and complete time to epoch and tell me days, hrs, min but why when I use sub datetounix it only count how many day like 09/30 - 09/23 = 7 days Could you help me to fix my sub datetounix. Thanks
Edit by thelenm: put <code> tags around code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: date time to unix
by Aristotle (Chancellor) on Oct 01, 2003 at 18:36 UTC | |
|
Re: date time to unix
by Nkuvu (Priest) on Oct 01, 2003 at 18:29 UTC | |
|
Re: date time to unix
by Roger (Parson) on Oct 02, 2003 at 07:46 UTC |