• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1305
  • Last Modified:

Getting system date as DD MMM YYYY

Hi,

Guess this is pretty simple if you know what you're doing, but all I need to know is the full code for getting the system date into a variable in a Perl Script in the following format:

eg) 25 DEC 1999

Many thanks,
Dave

0
dgb001
Asked:
dgb001
  • 3
  • 2
  • 2
  • +1
1 Solution
 
vaksCommented:
On UNIX you could do:

$date = `date +"%d %b %Y"`;

The month will, however, come as "Dec" and not "DEC".

Note that the ` looks like a small \

Regards
Vaks
0
 
dgb001Author Commented:
Yep, that's great - post it as an answer and I can throw you some points.

Thanks for your help,
Dave
0
 
prakashk021799Commented:
If you do a lot of date manipulation, get the module Date::Manip from a CPAN archive near you. It is a very useful module.

Once you have it, just do:

use Date::Manip;

# get system date in DD MMM YY format
$today = UnixDate('today', '%d %b %y');

# if you want the month in upper case,
# change the above line to:
$today = uc UnixDate('today', '%d %b %y');

For one time use, it might be overkill to use this module.
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
prakashk021799Commented:
#Change the year format to get 4-digit year (%y to %Y)

# get system date in DD MMM YYYY format
$today = uc UnixDate('today', '%d %b %Y');
0
 
dgb001Author Commented:
Thanks Prakashk,

That looks useful. In actual fact the previous comment proved to be just what I wanted for the current task, but your comments definitely look like something I can make more use of in the future.

Thanks very much,
Dave
0
 
vaksCommented:
On UNIX you could do:

$date = `date +"%d %b %Y"`;

The month will, however, come as "Dec" and not "DEC".

Note that the ` looks like a small \

Regards
Vaks
0
 
ozoCommented:
($date=localtime)=~s/\w+( \w+ )(\d+).* /$2\U$1/;
0
 
dgb001Author Commented:
Thanks ozo,

Dave
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now