I have 2 fields, date_added which is the date the record was added using the now() function, the other num_days which is the number of days before it gets deleted, values can be 30 or 180 days.
To get the days left before deletion i've got -
$query = qq!
SELECT UNIX_TIMESTAMP(DATE_ADD(date_added,INTERVAL num_days +1 DAY)) FROM table WHERE id=$user
!;
$sth = $dbh->prepare($query) or &cgierr("Unable to query. Reason: $DBI::errstr.");
$sth->execute or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");;
while (($u_date) = $sth->fetchrow_array) {
$diff=int((($u_date - time())/86400));
print "$diff";}
$sth->finish;
$dbh->disconnect;
works fine, but can any one think of a way to do it all within the select statement. I've tried everything I can think of, maybe there isn't a way.
Bob
http://totallyfreeads.com
To get the days left before deletion i've got -
$query = qq!
SELECT UNIX_TIMESTAMP(DATE_ADD(date_added,INTERVAL num_days +1 DAY)) FROM table WHERE id=$user
!;
$sth = $dbh->prepare($query) or &cgierr("Unable to query. Reason: $DBI::errstr.");
$sth->execute or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");;
while (($u_date) = $sth->fetchrow_array) {
$diff=int((($u_date - time())/86400));
print "$diff";}
$sth->finish;
$dbh->disconnect;
works fine, but can any one think of a way to do it all within the select statement. I've tried everything I can think of, maybe there isn't a way.
Bob
http://totallyfreeads.com