Date Formating in Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Formating in Perl
# 1  
Old 09-07-2008
Date Formating in Perl

Hi All,

Can anybody tell me why is there a "0" in my output of $date_today ?


Code:
#!/usr/local/bin/perl

$date_today = system "date '+%y%m%d'";
print "$date_today\n";

Output:
Code:
$ perl test4
080908
0

# 2  
Old 09-08-2008
Hi,
The value of $date_today is zero (the return value of system if successful, 0).

The output You see is first the result of the system date command, and then the value of $date_today.

Maybe You wanted something like

$date_today = `date '+%y%m%d'`;

/Lakris
# 3  
Old 09-08-2008
Hi Lakris,

Thanks a million!!
That's what i wanted!!Smilie
# 4  
Old 09-08-2008
Here's another example, a bit aside from your test, you can work / play with :
Code:
sub get_timestamp {
        @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
        @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
        ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
        $year = 1900 + $yearOffset;
        $theTime = "$hour:$minute:$second|$weekDays[$dayOfWeek].$months[$month].$dayOfMonth.$year";
        return $theTime;
}

I think I found it somewhere in the net, then I modified per my needs. The above subroutine call will return something like
Quote:
15:21:42|Fri.Sep.8.2008
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

[Perl] Different printf formating for different print options

Hi, Struggling with single quotes, double quotes, etc. I want to print a header line, followed by lines with actual values, based on a print option. In real life it is going to be something like 15 print options and 50 values. Output will be 1 header and several value lines. In this example... (5 Replies)
Discussion started by: ejdv
5 Replies

2. Emergency UNIX and Linux Support

Question on time and date formating..

can anyone one help me....to make date and time format...to following format for my file DATE TIME DD- MON- YEAR 24 Hours I have a need of format like this 12-Jan-2012 in one column, then time in 24 Hours in another column....please help...me... ... (4 Replies)
Discussion started by: nex_asp
4 Replies

3. 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

4. Shell Programming and Scripting

Formating of query variable in perl

Hi , I am facing error in perl when I assign a below query in a varibale $query because of new line charchters $query= SELECT XYZ , ABC , c2 , c3 , c4 FROM t1 how can i get rid of new line charchters with out changing the... (2 Replies)
Discussion started by: gvk25
2 Replies

5. 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

6. Shell Programming and Scripting

file formating in Perl

Hi, I am new to unix , I have a requirement for formating the input file and generate the output file as per the downstream requirement .. My application receiving a text input file having 4 field and my application need to check each field and if some value of a field is blank ..then it need... (1 Reply)
Discussion started by: julirani
1 Replies

7. 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

8. Shell Programming and Scripting

formating array file output using perl

Hello, I am trying to output the values in an array to a file. The output needs to be formated such that each array value is left jusified in a field 8 character spaces long. Also, no more than 6 fields on a line. For example: @array= 1..14; Needs to be output to the file like so: 1 ... (4 Replies)
Discussion started by: seismic_willy
4 Replies

9. Shell Programming and Scripting

formating date

Guys I have a date value like this in a table -> 2006-12-29 12:57:08(data type varchar2(25)) I am trying to subtract this column from sysdate. I am unable to do that. can u guys suggest me a way to do this.. (2 Replies)
Discussion started by: ragha81
2 Replies
Login or Register to Ask a Question