Sponsored Content
Full Discussion: perl DBI inserting date\time
Top Forums Shell Programming and Scripting perl DBI inserting date\time Post 302349797 by durden_tyler on Tuesday 1st of September 2009 09:36:15 PM
Old 09-01-2009
Quote:
Originally Posted by hcclnoodles
...
ive used now() before with PHP, maybe DBI in perl doesnt support it
...


That's a false statement. Perl DBI supports every single *valid* MySQL statement, if you are connected via the mysql driver.
If you can run the insert statement from the mysql client, you can very well execute it via Perl DBI.

Quote:
I did it this way in the end (in case its useful to others)


Code:
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
my $datetime = printf "%4d-%02d-%02d %02d:%02d:%02d\n",$year+1900,$mon+1,$mday,$hour,$min,$sec;
print $datetime;

This does the job but adds clutter as well, to your Perl program. More importantly, this picks up the client's local time. So if your MySQL server is in a different timezone, and if you want to add the server's time, then this will work but incorrectly.

tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Inserting Date&Time Stamp In Existing Log File

I am trying to insert a line with a date stamp in a file that is used to monitor activity in one of our directories. By doing this, I want to grep that file each day and go to the last entry for each time a error occurred and pull all errors generated if any exist. If error exists I want that error... (3 Replies)
Discussion started by: shephardfamily
3 Replies

2. Shell Programming and Scripting

PERL DBI module install

We ran into an issue trying to install DBI and DB2 modules for perl for AIX from the link http://www-306.ibm.com/software/data/db2/perl/ We tried to install the DBI module using bash# perl -MCPAN -e 'install DBI' command. However we ended up with the following error. Stop. ... (3 Replies)
Discussion started by: jerardfjay
3 Replies

3. Programming

perl dbi to oracle getting disconnect_all for oracle dbi help

hi i am trying to connect to an oracle database using dbi and i get this :: Driver has not implemented the disconnect_all method. at /opt/perl/lib/site_perl/5.8.0/sun4-solaris/DBI.pm line 575 END failed--call queue aborted. for all i know, the script was working earlier, but has... (1 Reply)
Discussion started by: poggendroff
1 Replies

4. Shell Programming and Scripting

Installing Perl DBI and DBD

Hi, i have some queries on installing the Perl DBI and the DBD Oracle. I know that i have to install the DBI first. I have the source files in a folder in my home directory.The commands to install arecd /home/DBI Perl Makefile.PL make make installI would like to know, after executing these... (4 Replies)
Discussion started by: new2ss
4 Replies

5. Shell Programming and Scripting

connect to MySQL from Perl using DBI

Hi, I want to connect perl with the mysql to select and so on but the connection don't work code #!/usr/bin/perl BEGIN { # PERL MODULES WE WILL BE USING use DBI; $dbh = DBI->connect('DBI:mysql:C:\Program Files\MySQL\MySQL Server 5.0\data\db1','','pass') or die $DBI::errstr;} #... (1 Reply)
Discussion started by: eng_shimaa
1 Replies

6. UNIX for Advanced & Expert Users

Perl's DBI Module on OS X - uninstallable?

i've been struggling with installing the Perl DBI & DBD modules all weekend, and I'm getting close, but no cigar as of yet. When I run the perl script db.pl I get the following mismatch error: Mon Apr 19 09:43:29 EDT 2010 /Library/Perl/DBD-mysql-4.011 -> peterv@MBP17.local<515>$: db.pl | tee... (0 Replies)
Discussion started by: peterv6
0 Replies

7. Shell Programming and Scripting

perl: help with DBI

Hi there, I have a bit of code similar to below (which ive actually got from perldoc, but mine is similar enough) $sth = $dbh->prepare(q{ SELECT region, sales FROM sales_by_region }); $sth->execute; my ($region, $sales); # Bind Perl variables to columns: $rv =... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

8. Shell Programming and Scripting

Date and Time in PERL

Hi, I want to get the current date and time and subtract 1 day to get to the previous day? I see timelocal( ) and (time) etc. How do I code this in PERL to get the previous day? Thanks Nurani (2 Replies)
Discussion started by: nurani
2 Replies

9. Shell Programming and Scripting

Creating a date (without time) in perl

I have a perl script that automatically runs on Mondays. I need to have it create a variable for last Monday's date thru that Sunday's date. example: 04-01-2011 thru 04-08-2011 Its reporting numbers for the previous week beginning with Monday and ending on Sunday. So i dont have to go in... (7 Replies)
Discussion started by: bbraml
7 Replies

10. Shell Programming and Scripting

Perl DBI error

Hi All, I installed DBI module in a non INC location and using it in my script via "use lib". But it throw the below error at the "use DBI" step. Please help Usage: DBI::_install_method(dbi_class, meth_name, file, attribs=Nullsv) at /xx/xxx/xxxxx/xxxxx/oracle/lib/DBI.pm/oracle/lib/DBI.pm line... (2 Replies)
Discussion started by: prasperl
2 Replies
DBIx::Class::Storage::DBI::mysql(3)			User Contributed Perl Documentation		       DBIx::Class::Storage::DBI::mysql(3)

NAME
DBIx::Class::Storage::DBI::mysql - Storage::DBI class implementing MySQL specifics SYNOPSIS
Storage::DBI autodetects the underlying MySQL database, and re-blesses the $storage object into this class. my $schema = MyDb::Schema->connect( $dsn, $user, $pass, { on_connect_call => 'set_strict_mode' } ); DESCRIPTION
This class implements MySQL specific bits of DBIx::Class::Storage::DBI, like AutoIncrement column support and savepoints. Also it augments the SQL maker to support the MySQL-specific "STRAIGHT_JOIN" join type, which you can use by specifying "join_type => 'straight'" in the relationship attributes It also provides a one-stop on-connect macro "set_strict_mode" which sets session variables such that MySQL behaves more predictably as far as the SQL standard is concerned. STORAGE OPTIONS
set_strict_mode Enables session-wide strict options upon connecting. Equivalent to: ->connect ( ... , { on_connect_do => [ q|SET SQL_MODE = CONCAT('ANSI,TRADITIONAL,ONLY_FULL_GROUP_BY,', @@sql_mode)|, q|SET SQL_AUTO_IS_NULL = 0|, ] }); AUTHORS
See "CONTRIBUTORS" in DBIx::Class LICENSE
You may distribute this code under the same terms as Perl itself. perl v5.16.2 2012-08-16 DBIx::Class::Storage::DBI::mysql(3)
All times are GMT -4. The time now is 03:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy