Results 1 to 4 of 4

Thread: date conversion

  1. #1
    Join Date
    Feb 2005
    Posts
    8

    Question Unanswered: 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

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

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

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •