Problem with date in perl!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with date in perl!!
# 1  
Old 10-28-2010
Problem with date in perl!!

Hi All,
I am facing an issue with perl..
I have a perl script that executes the stored procedure and puts the data in a file. In stord proc we have one date column also. In table from which it is fetching the data, date is in the form "14/03/2010 00:00:00.000" (DD/MM/YYYY). But when the perl script is putting the data in the file it is writing that date column as "Mar 14 2010 00:00AM". Not sure why this conversion is happening!! Though we are not using convert functions anywhere. I want the date in the same format as it is in the table "14/03/2010 00:00:00:00".

Please assist!!
Thanks in Advance!!
# 2  
Old 10-28-2010
Please paste the relevant code snippet. I'm guessing that you're using localtime. See localtime - perldoc.perl.org for changing the format.
# 3  
Old 10-28-2010
If I understood correctly, you have to convert date into your format, you can try the below select statement.

Code:
SELECT TO_CHAR(date_column, 'DD/MM/YYYY HH24:MI:SS') AS New_Date from tablename

# 4  
Old 10-28-2010
Let me clarify the issue that I am facing..

There is a table
create table MyTable
(
S_No int,
date datetime
)

The data in it is as :

select * from MyTable

1 14/03/2010 00:00:00.000
2 12/04/2010 00:00:00.000

Date is in DD/MM/YYYY format in the table.

But now when I am fetching the same data through perl and writing it in a file with pipe separated values, it is coming up as:

more file.txt:

S_No|date
1|Mar 14 2010 12:00AM
2|Apr 12 2010 12:00AM

The format of date is coming up as different in a file from what we have in table. I want it to be same as that of table.
While investigating, I also got to know that not only in perl, if we do simple isql for sybase and redirect the output to the file, date gets converted to 'Mar 14 2010 12:00AM' irespective of the format it is in the table.
What I am not getting is how unix/shell/perl script is converting the date themselves? and how do I keep it the way it is in table?

Thanks
# 5  
Old 10-28-2010
Try this perl code,
Code:
$dt="Mar 14 2010 12:00AM";
$new_dt=`date -d "$dt" '+%d/%m/%Y %T'`;
print $new_dt;

This User Gave Thanks to pravin27 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies

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

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

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

Problem with perl pattern for date

Hello Friends, I have been struck with a perl script for quite some time now. I have a log file which gives a date which is sometimes coming in this format Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 15:12:50 or sometimes in this format Script... (2 Replies)
Discussion started by: achak01
2 Replies

6. Shell Programming and Scripting

problem with date in perl

hi guys, i have a variable date that stores the current date....now i need to subtract 2 minutes from it...can someone tell me how to do it in perl.... (5 Replies)
Discussion started by: niteesh_!7
5 Replies

7. Programming

Date time problem while executing perl script.

Hi All, This Monday 15th March 2010, i have faced a weired issue with my Perl script execution, this script is scheduled to run at 1 minute past midnight on daily basis ( 00:01 EST ) generally for fetching previous business date , say if it is Monday it should give last Friday date, for Tuesday... (0 Replies)
Discussion started by: ravimishra
0 Replies

8. Shell Programming and Scripting

Date problem in perl

Hi, My script is here-- #!/usr/bin/perl no warnings "uninitialized"; use File::Copy; use File::stat; use Time::Local; use IO::Handle; use DateTime; use Getopt::Long; use File::Glob ':glob'; my $Summary; my $Individual; my $Diagnostics; my $All; (3 Replies)
Discussion started by: namishtiwari
3 Replies
Login or Register to Ask a Question