Hi susinthaa,
The answer, of course, is "it depends". What it depends on is just exactly what you want.
There is no built-in function that returns exactly "the date" (with no time-of-day). There is a function,
localtime, that gives you all the components of the date and time so that you can show/print the date/time in whatever format you want. See the doc for
localtime and also try the command "man strftime" at your *ix command prompt. For example the following perl code demonstrates multiple ways to "show the current date" and you can choose whatever is most suitable for your own purposes.
- #! /usr/bin/perl
-
use strict;
-
use POSIX qw(strftime);
-
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
-
$year += 1900;
-
my @moname = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
-
my $datestring = "$mday $moname[$mon] $year";
-
print "$datestring\n";
-
print "It is now ", scalar localtime, " \n";
-
print "Today is ", strftime ("%a %b %e %C%y", localtime), " \n";
-
As usual "there is more than one way to do it". The localtime function is clearly better if you plan to do any testing or calculation on the current time, but using strftime is a good alternative if all you want is a single string with a formatted date (or date/time). It depends on the availability of the POSIX module, but that should be available all or nearly all the time.
Best Regards,
Paul