Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Date problem

Status
Not open for further replies.

PerlElvir

Technical User
Aug 23, 2005
68

HI all, I have this situation: I want to get all dates between curent date and 30 days, so I want to get now:
2006-05-22
2006-05-23
2006-05-24
2006-05-25
2006-05-26
.
.
.
2006-06-21

Now I use this script and I get only last date 2006-06-21.

SO can some one help ;)



#!/usr/bin/perl -w

use DBI;


sub jet_emul()
{

$dbh = DBI->connect("DBI:mysql:acerigel:localhost", "root", "");




$query = "SELECT DATE_ADD(CURDATE(),INTERVAL 30 DAY);";
my $sth = $dbh->prepare($query);
$sth->execute();
while (my @date = $sth->fetchrow_array())
{


$g_date_fin = $date[0];
print $g_date_fin."\n";

}
$sth->finish();



$dbh->disconnect();
}

jet_emul();



 
Why are you using MySQL for this, since you're not selecting any data from the database?

Have a look at the Date::Calc module on CPAN for a way of doing this without requiring the database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top