Query - Value

Query - Value

am 15.06.2004 16:49:11 von Werner Otto

Hi,

I have a query:

$query = "SELECT (UNIX_TIMESTAMP('$stat_tud_dte
$stat_tud_tme')-UNIX_TIMESTAMP('$stat_stu_dte $stat_stu_tme))";
my $sth = $dbh->prepare($query);
$sth->execute();

How do I get the results into a variable?

--
Kind Regards,
Otto

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Query - Value

am 15.06.2004 18:35:42 von Christopher Pryce

On Jun 15, 2004, at 9:49 AM, Werner Otto wrote:

> I have a query:
>
> $query = "SELECT (UNIX_TIMESTAMP('$stat_tud_dte
> $stat_tud_tme')-UNIX_TIMESTAMP('$stat_stu_dte $stat_stu_tme))";
> my $sth = $dbh->prepare($query);
> $sth->execute();
>
> How do I get the results into a variable?

Two ways:
1) Since you know that the result set contains one row, call:

my $row = $sth->fetch(); # short for fetchrow_arrayref
print $row->[0], "\n";

2) or don't prepare the query, and use selectrow_array:
my ($row) = $dbh->selectrow_array( $query );
print $row, "\n";

But the better question is, if all you want are Unix time strings, why
not use a more portable Perl solution like Time::Local or the Module
Date::Parse ?

use Date::Parse qw(str2time);
# assumes that the values are YYYY-MM-DD HH:MM:SS
my $offset = str2time("$stat_tud_dte $stat_tud_tme") -
str2time("$stat_stu_dte $stat_stu_tme");


cp


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Query - Value

am 15.06.2004 18:35:42 von Christopher Pryce

On Jun 15, 2004, at 9:49 AM, Werner Otto wrote:

> I have a query:
>
> $query = "SELECT (UNIX_TIMESTAMP('$stat_tud_dte
> $stat_tud_tme')-UNIX_TIMESTAMP('$stat_stu_dte $stat_stu_tme))";
> my $sth = $dbh->prepare($query);
> $sth->execute();
>
> How do I get the results into a variable?

Two ways:
1) Since you know that the result set contains one row, call:

my $row = $sth->fetch(); # short for fetchrow_arrayref
print $row->[0], "\n";

2) or don't prepare the query, and use selectrow_array:
my ($row) = $dbh->selectrow_array( $query );
print $row, "\n";

But the better question is, if all you want are Unix time strings, why
not use a more portable Perl solution like Time::Local or the Module
Date::Parse ?

use Date::Parse qw(str2time);
# assumes that the values are YYYY-MM-DD HH:MM:SS
my $offset = str2time("$stat_tud_dte $stat_tud_tme") -
str2time("$stat_stu_dte $stat_stu_tme");


cp


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Query - Value

am 16.06.2004 12:23:43 von Werner Otto

Any idea how to get the string in time format back to days or a specific
date?

>
> On Jun 15, 2004, at 9:49 AM, Werner Otto wrote:
>
>> I have a query:
>>
>> $query = "SELECT (UNIX_TIMESTAMP('$stat_tud_dte
>> $stat_tud_tme')-UNIX_TIMESTAMP('$stat_stu_dte $stat_stu_tme))";
>> my $sth = $dbh->prepare($query);
>> $sth->execute();
>>
>> How do I get the results into a variable?
>
> Two ways:
> 1) Since you know that the result set contains one row, call:
>
> my $row = $sth->fetch(); # short for fetchrow_arrayref
> print $row->[0], "\n";
>
> 2) or don't prepare the query, and use selectrow_array:
> my ($row) = $dbh->selectrow_array( $query );
> print $row, "\n";
>
> But the better question is, if all you want are Unix time strings, why
> not use a more portable Perl solution like Time::Local or the Module
> Date::Parse ?
>
> use Date::Parse qw(str2time);
> # assumes that the values are YYYY-MM-DD HH:MM:SS
> my $offset = str2time("$stat_tud_dte $stat_tud_tme") -
> str2time("$stat_stu_dte $stat_stu_tme");
>
>
> cp
>
>

--
Kind Regards,
Werner Otto

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Query - Value

am 16.06.2004 12:23:43 von Werner Otto

Any idea how to get the string in time format back to days or a specific
date?

>
> On Jun 15, 2004, at 9:49 AM, Werner Otto wrote:
>
>> I have a query:
>>
>> $query = "SELECT (UNIX_TIMESTAMP('$stat_tud_dte
>> $stat_tud_tme')-UNIX_TIMESTAMP('$stat_stu_dte $stat_stu_tme))";
>> my $sth = $dbh->prepare($query);
>> $sth->execute();
>>
>> How do I get the results into a variable?
>
> Two ways:
> 1) Since you know that the result set contains one row, call:
>
> my $row = $sth->fetch(); # short for fetchrow_arrayref
> print $row->[0], "\n";
>
> 2) or don't prepare the query, and use selectrow_array:
> my ($row) = $dbh->selectrow_array( $query );
> print $row, "\n";
>
> But the better question is, if all you want are Unix time strings, why
> not use a more portable Perl solution like Time::Local or the Module
> Date::Parse ?
>
> use Date::Parse qw(str2time);
> # assumes that the values are YYYY-MM-DD HH:MM:SS
> my $offset = str2time("$stat_tud_dte $stat_tud_tme") -
> str2time("$stat_stu_dte $stat_stu_tme");
>
>
> cp
>
>

--
Kind Regards,
Werner Otto

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Query - Value

am 16.06.2004 14:41:29 von Christopher Pryce

On Jun 16, 2004, at 5:23 AM, Werner Otto wrote:

> Any idea how to get the string in time format back to days or a
> specific date?

perldoc -q localtime


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Query - Value

am 16.06.2004 14:41:29 von Christopher Pryce

On Jun 16, 2004, at 5:23 AM, Werner Otto wrote:

> Any idea how to get the string in time format back to days or a
> specific date?

perldoc -q localtime


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org