473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Is there any command to show the current date in perl?

Hi,

Is anybody knows that how to display the current date in perl?
As I am new to perl, I find some difficulties.
please help me.

Thanks & Regards,
susi
Jun 22 '07 #1
2 6255
prn
254 Expert 100+
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.
Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/perl
  2. use strict;
  3. use POSIX qw(strftime);
  4. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
  5. $year += 1900;
  6. my @moname = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
  7. my $datestring = "$mday $moname[$mon] $year";
  8. print "$datestring\n";
  9. print "It is now ", scalar localtime, " \n";
  10. print "Today is ", strftime ("%a %b %e %C%y", localtime), " \n";
  11.  
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
Jun 22 '07 #2
KevinADC
4,059 Expert 2GB
I think the real answer is: do your own school work. Anyone stuck on how to display the date with perl simply has not opened their perl book. And if you don't have a book, the answer is easily found with a search engine on the internet.

Prn was kind enough to indulge you but don't expect people to continue to help you unless you show some effort.

Kevin
Jun 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Robert | last post by:
I am using the php4-cgi Debian package which is based on PHP 4.3.4. I have problems when running php4 on the command line. If I say something like $ php4 index.cgi a number of variables...
1
by: Ben Floyd | last post by:
It goes like this: Im converting a perl script that executes a command on each result of a directory listing. In perl, all is well. In Python, using approximately the same logic creates a...
4
by: lkrubner | last post by:
I'd like to write a PHP script to be used from the command line on a Unix machine. I'd like for the script to put together a string, turn it into a web page, print it, then return control the...
4
by: Rick | last post by:
Hello, I currently use a field that I have set up to keep notes in. It is a memo data type field. It looks like a simple box, and I typically time and date stamp my notes as I enter them. For...
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
1
by: jmarr02s | last post by:
I created a subform with 4 separate fields (textboxes) each containing an 8 digit date I want the most current date to show in each of the four fields So under properties for the subform...
4
stormrider
by: stormrider | last post by:
Hi all, I'm trying to implement a Perl structure. My small program will do the followings; Take the birth date of the user as input. (Month's will be input as strings.) Take the current time...
0
by: khushnuma | last post by:
Hi I need to be able to ftp a file from its current location to another folder in a different server. This has to be done as part of a perl script. Can anyone please tell me a command / script to...
2
by: rimvydazas | last post by:
Hi guys, I have a script which deletes necessary entries on specific date. Here is the script: #!/usr/bin/perl -w use DBI; my $dbh = DBI->connect( "dbi:mysql:test", "newbie", "")
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.