If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > date conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-16-05, 22:14
shan79 shan79 is offline
Registered User
 
Join Date: Feb 2005
Posts: 8
Question date conversion

Hi,

I need to convert in perl a datetime variable bcp'ed out from a sybase database, which is in format 'Feb 4 2005 12:00:00:000AM'
to the following format '20050204' dropping the time part.

Can anybody please give me some ideas on how to do this?

Thanks,
shan
Reply With Quote
  #2 (permalink)  
Old 02-16-05, 23:35
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,613
There are probably a gazillion more perl-ish ways, but I'd probably use:
Code:
$bcp = "Feb 4 2005 12:00:00:000AM";

%month = ("Jan", 1, "Feb", 2, "Mar", 3, "Apr", 4, "May", 5, "Jun", 6
,  "Jul", 7, "Aug", 8, "Sep", 9, "Oct", 10, "Nov", 11, "Dec", 12);

@a = split / /, $bcp;
printf "%04d%02d%02d\n", $a[2], $month{$a[0]}, $a[1];
-PatP
Reply With Quote
  #3 (permalink)  
Old 02-17-05, 19:54
shan79 shan79 is offline
Registered User
 
Join Date: Feb 2005
Posts: 8
Thanks! This worked for me. I had to do some manipulation since there were more white spaces in my incoming date format. But it works.
Reply With Quote
  #4 (permalink)  
Old 02-17-05, 22:47
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,613
Oh heavens! I should have thought of that... Just add a trailing + to the split pattern and life should be way more gooder yet even.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On