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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need date in format 20060913 1

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
HI,

What is the fastest way to get the date in format 20060913 ?

Thanks

Long live king Moshiach !
 
That really depends on how you're gathering the date you need. But I'd suggest checking out the sprintf function.

- George
 
and the substr function, and perhaps the Date::Manip module, but as George says, it all depends on where your dates coming from,
Code:
my @dates=localtime();
$dates[5]+=1900;
$dates[4]++;
my $date = sprintf("%0.2d", $dates[5]).sprintf("%0.2d", $dates[4]).sprintf("%0.2d", $dates[3]);
print $date;
will return the system time in the format you require

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Also you could check out Time::Format - it requires simple installation (save the .pm file to your Perl lib as Time/Format.pm)

Code:
use Time::Format qw(time_format);
print time_format ('yyyymmdd');

This module is useful when you do a lot of time format operations, rather than dealing with localtime and manipulating variables from that yourself.
 
Thanks to all,
ended up yesterday with :

my $TIME=localtime;
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$year += 1900;
$mon+=1;
unless ($mon =~ /\d\d/) {
$mon = "0" . $mon;
}
my $DATE=$year . $mon . $mday;


However will try the Time::Format later on.

Long live king Moshiach !
 
Code:
use POSIX ('strftime');
my $date = strftime "%Y%m%d", localtime;
print $date;
 
Moshaich,

your bit of script will be susceptible to single digit days ...

--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top