Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem fromating fields

Status
Not open for further replies.

veteq

Technical User
Dec 7, 2004
23
CA
I am not sure where to start on this one

I wrote a PM file that looks after logging of all activity taking place with the main application.

code
---------------------------------------------------------
$finalTime= (localtime(time))[2] . ":" . (localtime(time))[1] . ":" . (localtime(time))[0];
$finalDate = (localtime(time))[3] . "-" .
$getmonth{(localtime(time))[4]} .
"-" .( (localtime(time))[5]+1900) ;
-----------------------------------------------------------
the problem that I am running into is with dropped 0s. If the time or date have a leading 0 in it, the variable drops it.

e.g.

10:07:05 becomes 10:7:5

How can I resolve this.....?

thank you
 
Try this:

Code:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$year += 1900;
$mon += 1;

my $finalTime =  (sprintf "%02d:%02d:%02d", $hour, $min, $sec);
my $finalDate = (sprintf "%02d/%02d/%04d", $mon, $mday, $year);

- Rieekan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top