Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Date/Time conversion Message-ID: <1991May7.221323.7866@jpl-devvax.jpl.nasa.gov> Date: 7 May 91 22:13:23 GMT References: <1991May07.184931.19141@osh3.OSHA.GOV> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 29 In article <1991May07.184931.19141@osh3.OSHA.GOV> chip@osh3.OSHA.GOV (Chip Yamasaki) writes: : I have a question on Date and Time conversions. I am writing a Perl : script to parse the UUCP logfiles to record the information in a : database. The logfiles contain the date and time information in a : format like: : : 5/6-0:09:49 : : I would like to be able to take this and turn it back into the Unix : clock time (seconds since . . .). If I have to I could load these : values into a tm type structure, but I can't find a function for that : either. : : Does anybody out there have a function like this in their Perl library? Anyone with 4.0 does. Incant this: ($thismon, $thisyear) = (localtime)[4,5]; require 'timelocal.pl'; ($mon,$mday,$hr,$mn,$sc) = $date =~ m#(\d+)/(\d+)-(\d+):(\d+):(\d+)#; $logyear = $thismon || $mon != 12 ? $thisyear : $thisyear - 1; $mon--; $secs_since_1970 = &timelocal($sc,$mn,$hr,$mday,$mon,$logyear); The fancy stuff just lets you analyze a December log in January. You might need to pass an extra argument to &timelocal to account for Daylight Savings Time. Larry