Re: perl - MySQL - date manipulation
- From: "Octavian Rasnita" <orasnita@xxxxxxxxx>
- To: <programmingblind@xxxxxxxxxxxxx>
- Date: Tue, 28 Oct 2008 13:18:39 +0200
Hi,
You can use either:
select current_date() + interval 30 day as future_day;
and the column name will be "future_day", or you can use:
select current_date() + interval 30 day;
and fetch from the database using an array or arrayref and not a hashref, like:
my $sth = $dbh->prepare("select current_date() + interval 30 day");
$sth->execute;
my ($future_date) = $sth->fetchrow_array;
$sth->fetchrow_array returns an array and $sth->fetchrow_arrayref returns an
array ref.
Octavian
----- Original Message -----
From: "Lamar Upshaw" <lupshaw@xxxxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, October 28, 2008 1:01 PM
Subject: Re: perl - MySQL - date manipulation
> Thanks for this. I think what's confusing me, is how to use perl to
> accomplish this. It seems perl depends on a table collumn name for the hash,
> but when working with the date, with MySQL, it doesn't return a collumn name
> for the hash. I hope I'm explaining this well. lol :)
>
> With All Respect,
> Upshaw, Lamar T
> ----- Original Message -----
> From: "Octavian Rasnita" <orasnita@xxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Tuesday, October 28, 2008 3:46 AM
> Subject: Re: perl - MySQL - date manipulation
>
>
> Hi,
>
> If you need to use a database, it is easier to use the database for
> calculations.
>
> You can use:
>
> current_date() + interval 30 day
> or
> current_date - interval 30 day
> or
> '2008-10-15' + interval 30 day;
> or
> current_date() + interval 1 month;
>
> There are many date calculations you can use in MySQL which you can find
> more about in the MySQL manual.
>
> Octavian
>
> ----- Original Message -----
> From: "Lamar Upshaw" <lupshaw@xxxxxxxxxxxxxx>
> To: <programmingblind@xxxxxxxxxxxxx>
> Sent: Tuesday, October 28, 2008 12:29 PM
> Subject: perl - MySQL - date manipulation
>
>
>> I'm working with perl and MySQL for CGI scripting, and I need to be able
>> to
>> calculate dates. How do I have MySQL calculate 30 days from now, and
>> return
>> it to perl? Or, would it be easier to calculate 30 days from now in perl
>> instead? I understand how to get the present date and time in perl, but I
>> can't figure out how to calculate other dates. Truthfully, I'd rather do
>> this in MySQL and have it return to perl, because the calculated date will
>> be saved in a database table whether I calculate it using perl, or MySQL
>> anyway.
>>
>> With All Respect,
>> Upshaw, Lamar T
>>
>> __________
>> View the list's information and change your settings at
>> http://www.freelists.org/list/programmingblind
>>
> __________
> View the list's information and change your settings at
> http://www.freelists.org/list/programmingblind
>
> __________
> View the list's information and change your settings at
> http://www.freelists.org/list/programmingblind
>
__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind
- References:
- lynix question:
- From: Charles E. Black
- Re: lynix question:
- From: Chris Hallsworth
- RE: lynix question:
- From: Charles E. Black
- RE: lynix question:
- From: Ken Perry
- Re: lynix question:
- From: Rick Harmon
- String Replace for Special Chars using Perl?
- From: Bryan Garaventa
- Re: String Replace for Special Chars using Perl?
- From: Bryan Garaventa
- perl - MySQL - date manipulation
- From: Lamar Upshaw
- Re: perl - MySQL - date manipulation
- From: Octavian Rasnita
- Re: perl - MySQL - date manipulation
- From: Lamar Upshaw
Other related posts:
- » perl - MySQL - date manipulation
- » Re: perl - MySQL - date manipulation
- » Re: perl - MySQL - date manipulation
- » Re: perl - MySQL - date manipulation
- » RE: perl - MySQL - date manipulation
- » Re: perl - MySQL - date manipulation
- lynix question:
- From: Charles E. Black
- Re: lynix question:
- From: Chris Hallsworth
- RE: lynix question:
- From: Charles E. Black
- RE: lynix question:
- From: Ken Perry
- Re: lynix question:
- From: Rick Harmon
- String Replace for Special Chars using Perl?
- From: Bryan Garaventa
- Re: String Replace for Special Chars using Perl?
- From: Bryan Garaventa
- perl - MySQL - date manipulation
- From: Lamar Upshaw
- Re: perl - MySQL - date manipulation
- From: Octavian Rasnita
- Re: perl - MySQL - date manipulation
- From: Lamar Upshaw