http://qs321.pair.com?node_id=513282

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on How to insert local time and date to MS-Access database using PERL program

Replies are listed 'Best First'.
Re: How to insert local time and date to MS-Access database using PERL program
by jkva (Chaplain) on Dec 01, 2005 at 14:31 UTC
    UPDATE : Added warnings and strict... have to give a good example.
    #!/usr/bin/perl use strict; use warnings; print "This code works perfectly!";

    ;)

    On a more serious note, Perl and Microsoft Access might be of help.
Re: How to insert local time and date to MS-Access database using PERL program
by davorg (Chancellor) on Dec 01, 2005 at 14:36 UTC

    Well, it's impossible to give you "perfect workable code" as we know nothing about your system or your database structure. And besides, we're not really all that keen on just handing out code to people without seeing that they've made some effort on the problem first.

    So I suggest that you take a look at the DBI and DBD::ODBC modules and see if they are any help to you.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: How to insert local time and date to MS-Access database using PERL program
by bobf (Monsignor) on Dec 02, 2005 at 04:17 UTC

    As others have already mentioned, it really would be better (for both you and us) if you posted code that shows us your attempt at solving the problem. Nonetheless, I wrote this sub a while ago, and I decided to post it here in the event that you or someone else may find it useful. There are plenty of references to help you figure out how to use DBI to insert the data into the database, so you're on your own for that part (if you get stuck feel free to post another question, but show us what you've tried when you do).

    The sub takes a date/time string as an argument and uses the Date::Manip module to parse and calculate the corresponding Microsoft date and time serial numbers.

    use strict; use warnings; use Date::Manip; Date_Init( "TZ=CST6CDT" ); # see Date::Manip docs about this my $datestring = 'Dec 1, 2005 11:17:20 PM'; my ( $date_sn, $time_sn ) = calc_serial_numbers( $datestring ); print "date SN = $date_sn\n"; # 38687 print "time SN = $time_sn\n"; # 0.97037037 sub calc_serial_numbers { # This sub takes a string containing a date and time, and # calculates the corresponding Microsoft date and time serial # numbers. Note there is a bug in the MS calculation (for # historical reasons MS calculates 1900 as a leap year; source # is Date::Calc docs) which necessitates adding an extra day to # the date serial number (therefore it is calculated based on # 12-31-1899 rather than 1-1-1900). These serial numbers are # suitable for storing in MS Access as a date/time field, and # can also be used in MS Excel. my ( $datetimestring ) = @_; # calculate the number of days since 12-31-1899 # (or 1-1-1900, according to MS) my $parsed_date = ParseDate( $datetimestring ); my $date_delta = DateCalc( 'Dec 31, 1899', $parsed_date ); my $date_sn = Delta_Format( $date_delta, 0, ( '%dh' ) ) + 1; # calculate the fraction of the current day, in seconds # 60*60*24 = 86400 seconds per day my $daystart = Date_SetTime( $datetimestring, '00:00:00' ); my $time_delta = DateCalc( $daystart, $parsed_date ); my $num_sec = Delta_Format( $time_delta, 0, ( '%sh' ) ); my $time_sn = sprintf( "%.8f", $num_sec/86400 ); return( $date_sn, $time_sn ); }