Sponsored Content
Full Discussion: Date in Perl
Top Forums Shell Programming and Scripting Date in Perl Post 302256277 by cbkihong on Sunday 9th of November 2008 04:27:29 AM
Old 11-09-2008
The date command outputs a newline after the date. That's expected because you get the same if you run the same command in a shell.

You can chomp() the variable to remove the trailing newline, but ...

Why don't you just get the date with perl alone in the first place, like this?

Code:
use Time::localtime;
$date_today = sprintf("%02d%02d%02d", (localtime->year+1900) % 100, localtime->mon+1, localtime->mday);

If you are willing to install extra module, there are even easier ways to generate arbitrary date strings.
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies

2. Shell Programming and Scripting

date in perl

im having trouble with this... i can do it in awk but perl is giving me trouble. i want to test for the previous 3 days, today, and the coming three days. heres the code: #!/usr/bin/perl chomp($info=`date +%b%d`); $info =~ tr///; if ($info =~ m/^(*)()$/) { $info = "$1.0.$2"; } ... (4 Replies)
Discussion started by: nomkev
4 Replies

3. Shell Programming and Scripting

Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl

Hi , This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated. use Time::Local; my $d = $ARGV; my $t = $ARGV; my $m = ""; @d = split /\//, $d; @t = split /:/, $t; if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies

4. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

5. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

6. Shell Programming and Scripting

Fetch date of 7 years back from current date in Perl

$beginDate = substr(DateCalc("today", "-7Days"),0,8); This fetches the date 7 days back Can I fetch the date before 7 years from todays date in Perl using same syntax Use code tags, see PM. (3 Replies)
Discussion started by: parthmittal2007
3 Replies

7. Shell Programming and Scripting

Today's date using Perl?

Easiest way to get it in the form of MM/DD/YY for Perl 5.8.8? Thanks (4 Replies)
Discussion started by: stevensw
4 Replies
All times are GMT -4. The time now is 11:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy