
brian.hayes
User
Jan 16, 2000, 5:02 PM
Post #2 of 5
(441 views)
|
This isn't exactly what your looking for but it will help.. I comented this one to try to explain what is going on. Just change it around to fit what you need. Sorry for not doing this for you. If no one reply's soon I will take a better look for you. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> ## This will print out date in a readable format. ## print gdate('/','yy/mm/dd','xxxx'); sub gdate{ ## Must have three values passed to sub gdate. ## &gdate('/','dd/mm/yy','xx') format. ## first is the spacer between day month year. ## Second is the layout of date. ## Third is display 2 or 4 value year in date. ## Any value under two digets will produce two ## year value. Default is four. I.E. 2000. if (!defined($_[0]) or !defined($_[1]) or !defined($_[2])){ return "gdate('/','dd/mm/yy','0000') Missing vars.."; } my $spacer = $_[0] ; my $format = $_[1] ; my $myyear = length($_[2]) ; ## Must have some sort of mm/dd/yy format layed out.. if ($format eq ''){ return "Error! gdate('/','dd/mm/yy','0000') format."; exit(0); } ## Made it this far lets set some vars from out local time. my $now = localtime(time); ## Split the vars from local time to readable vars.... my($week, $month, $day, $time, $year) = split(/\ /,$now); ## Set vars to them selves.. This just prevents error log buildup.. $week = $week; $day = $day; $time = $time; $year = $year; $month = $month; ## If we only want a two char output for year. Default is 1999,2000,2001. if ($myyear <= 2) { $myyear = $year; my ($a,$b,$c,$d) = split(//,$myyear); $year = "$c$d"; } ## Setup loop here with value=value, statments for text to number. my @rm = ("Jan=1", "Feb=2", "Mar=3", "Apr=4", "May=4", "Jun=6", "Jul=7", "Aug=8", "Sep=9", "Oct=10", "Nov=11", "Dec=12"); my $rm = ""; ## Go through all months and replace text value to numeric values.. foreach $rm (@rm) { ## Slow down a little just incase we are getting hit hard. #sleep(1); ## Split each value=value into $k and $v. $k is left side ## and $v is right ## side of $rm's value. my ($k , $v) = split(/=/, $rm); ## Now match current system month to a numeric value from $rm. if($k eq $month) { ## replace text with number value.. $month = $v; ## Determin layout, print and return to caller. if ($format eq 'mm/dd/yy'){ return "$month$spacer$day$spacer$year"; } if ($format eq 'mm/yy/dd'){ return "$month$spacer$year$spacer$day"; } if ($format eq 'dd/mm/yy'){ return "$day$spacer$month$spacer$year"; } if ($format eq 'dd/yy/mm'){ return "$day$spacer$year$spacer$month"; } if ($format eq 'yy/dd/mm'){ return "$year$spacer$day$spacer$month"; } if ($format eq 'yy/mm/dd'){ return "$year$spacer$month$spacer$day"; } } ## End if for $k eq $month... } ## End looping based on values in @rm. ## If you make it this fare without returning then give default UNIX style format. ## and return that value. return $now; } ## End sub. </pre><HR></BLOCKQUOTE> Brian Hayes [This message has been edited by Borderline (edited 01-16-2000).]
|