SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What can we use in perl to retreive a date in the Locale format?

    What can we use in perl to retreive a date in the Locale format?

    Basically, I am retrieving some data from a database table via a stored proc. The data in the table is in English date format i.e dd/mm/yyyy. However, the perl scrip somehow converts this into mm/dd/yyyy.

    I have used setlocale(LC_ALL, "english"); - but not doing the job.

    Any ideas what I can do here ?

  2. #2
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It might have nothing to do with locale. If the date is actually stored as a string (in stead of raw or epoch seconds) then most likely the perl script is parsing it and reformatting the date to the authors requirements. If the script isn't too big post it.

  3. #3
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am executing a stored proc which brings back results from a table , sample of which is below and date is in 2nd columd which is of desired format i.e dd/mm/yyyy.

    2090 anv.pr.ia.rbs.elp 15/06/2009 19:48:43.000 107
    2090 anv.pr.sod.load.elp 16/06/2009 03:14:38.000 14
    2090 anv.pr.capital.extract.elp 16/06/2009 04:35:19.000 5
    2090 anv.pr.birt.batch.elp 16/06/2009 07:09:59.000 154
    2090 anv.pr.margin.feed.elp 16/06/2009 06:02:34.000 2
    2090 anv.pr.cres.auto.repr.elp 16/06/2009 06:50:56.000 0
    2090 ALGO 16/06/2009 15:30:24.300 137
    2090 ECN 16/06/2009 15:30:26.160 371
    2090 GCM Orbit 16/06/2009 15:30:27.303 63
    2090 Repo Trades 16/06/2009 15:30:28.483 747
    2090 IA 16/06/2009 15:30:30.316 9392

    However my script outputs mm/dd/yyyy - script is below..

    #!/bin/sh
    #/** -*- perl -*-
    #
    # KPIData: Produce KPI relevant data for Anvil.
    #
    # Notice: Copyright (c) Anvil. All Rights Reserved.
    # $Date: $
    # Component: $Source: $
    #
    # $RCSfile: $
    # $Author: $
    # $Revision: $
    #
    # **/

    . ${REPOanvilrepo}/bin/shdefs

    exec $PERL -w -x "$0" "$@"

    #!perl
    #line 22

    use Env qw/REPO/;
    use Arts::SybLib;
    use Env qw/REPO/;
    use Arts::Useful;
    use Arts:ateTime;
    use Arts::Vismux;
    use POSIX;

    my $fail_jobid = "KPI_FAIL";
    my $prog = "KPI_DATA";
    my $cleanup;
    my $dbh;
    my $sth;


    ########################################################################

    sub main {

    setlocale(LC_TIME, "english");


    my $rfile = "/home/khanri/temp/KPI.csv";
    my $inputFilePath = "/home/khanri/temp/";
    my $filedate = `date +"%d%m%Y"`;
    chomp $filedate;

    my $tab_file = $inputFilePath . "anv.elp.run.report." .$filedate. ".txt";
    if (not -e $tab_file) {
    die ("$tab_file from has not arrived from Autosys, try later.\n");
    }

    $dbh = connect_to_db('ChopBlanks' => 1);

    my $delete_old = 'truncate table batch_timings';
    $sth = $dbh->prepare($delete_old);
    $sth->execute or die("Deleting existing batch list failed \n");

    system "$REPO/bin/DoBcpIn", 'batch_timings', $tab_file || die("Cannot BCP $tab_file\n");

    my @header = ( 'Catalogue Id', 'KPI id', 'Business Date', 'KPI Value' );

    my $process_kpi = 'exec build_kpi';
    $sth = $dbh->prepare($process_kpi);
    $sth->execute;
    my $results = $sth->fetchall_arrayref;
    $sth->finish();


    open OUT, ">$rfile" or die "Can't open $rfile. $!\n";

    print OUT join(",",@header) . "\n";

    foreach my $rec ( @{$results} ) {
    foreach my $column (@{$rec}) {
    if (!$column) {
    print OUT " ";
    } else {
    print OUT $column;
    }
    print OUT ",";
    }
    print OUT "\n";
    }


    close OUT;

    exit(0);

    }
    ########################################################################

    main();

  4. #4
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry date is 3rd column in sample table

  5. #5
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry but after looking at your code I am clueless as to what the source of the problem is. Try www.perlmonks.com or www.stackoverflow.com


Bookmarks

Posting Permissions

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