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

getting and formatting date 1

Status
Not open for further replies.

math

Programmer
Mar 21, 2001
56
BE
hi,

I have writen a script that gets the date... It works fine on my windows2000 IIS server, but... The script must eventually run on a american server running on UNIX.
All I know is the following:
the perl-dir = /usr/bin/perl
the date-dir = /bin/date

What I need is the current date in DDMMYYYY

The script that works on IIS:
Code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$tmpdate = scalar localtime;
($wday, $mnth, $day, $hour, $year) = split(/ /,$date);
$date = join("",$day,$mnth,$year);
print "$date";
All I need to know is how I get the same result but on UNIX... How do I use the /bin/date dir??

Thanx,
math
 
Hi Mate,

well I've been doing date calculations and such for a looong time because a lot of the stuff I write turns out to be based on times and such, and the best way I've found for any kind of time usuage on windows or unix system is storing localtime into an array, it a lot easier to handle and really only takes about 5 lines.

(@days) = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday' , 'Saturday');
(@names) = ('January','February','March','April','May','June','July','August','September','October','November','December');
@thetime=localtime;
$month = $names[$thetime[4]];
$year = $thetime[5] + 1900;
$weekday = $days[$thetime[6]];
$date = "$weekday, $month $thetime[3]";

That's to get the date in a nice format, I have that little chunk laying around so I thought I'd paste it so maybe you'll get some use out of it.

But to get the format you want,

@time=localtime;
$year = $time[5] + 1900;
$date = "$time[3]/$time[4]/$year";

This is the order localtime stores information into an array, 0 - 8

$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst

If this doesn't help any, try


Perldoc.com is a great resouce,

Well, good day,

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top