Gossamer Forum
Home : General : Perl Programming :

Adding x years to date and displaying

Quote Reply
Adding x years to date and displaying
Hi Guys.

Ive followed a post on here.

http://www.gossamer-threads.com/...Mysql%20Date;#115721

And managed to get my date displaying correctly.

What i want to do now is add x ammount of years to the date and display this date.

I have a field in a table called domain_period_yr which is listed as a numerical value 1, 2, 3, etc. i want to add these years to the initial date and display this.

Can this be done?
Regards

Mark
http://www.host4.me.uk

No doubt i'll be back for more answers!
Quote Reply
Re: [mdj1] Adding x years to date and displaying In reply to
You could do it in mysql:

SELECT DATE_FORMAT(DATE_ADD(your_date_col, INTERVAL domain_period_yr YEAR), "however you want it formatted") FROM your_table

See: http://www.mysql.com/..._time_functions.html for how to format it.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Adding x years to date and displaying In reply to
OK,

I have the following,

Code:
my $query_domain = qq{select * from order_d, order_m where DATE_SUB(domain_date,INTERVAL $queryresult_conf[0] DAY) <= DATE_SUB(curdate(),INTERVAL domain_period_yr YEAR) and order_m.order_id=order_d.order_id and order_m.user_id=$user_id and domain_reg="y" };
#print "query_domain = " . $query_domain . "<br>";
my $ret_mysql_domain = select_query($query_domain);
my $numrows_domain = $ret_mysql_domain->rows;
my @queryresult_domain;

Which works just the way i want, displaying all the info i need, except the renewal date. which i think is worked out in the query, but how do i display it?

Or am i wrong?
Regards

Mark
http://www.host4.me.uk

No doubt i'll be back for more answers!
Quote Reply
Re: [mdj1] Adding x years to date and displaying In reply to
OK, OK, ignore the last post.

This is what i have set up as a sub in my sub file.

sub getRenewalDate
{
my($renewal_date) = @_;


##connection();

my $query = qq{SELECT DATE_FORMAT(DATE_ADD(domain_date, INTERVAL domain_period_yr YEAR), "%D,%m,%Y") FROM order_d};
my $ret_mysql = select_query($query);
my @queryresult;
@queryresult = $ret_mysql->fetchrow_array();


return $queryresult[0];

}#end of getRenewalDate subroutine


Then in my working file i have the following query which displays the domains due for renewal for the specific user.

############ getting all the registered domains whose days left from expiration=renew_mails_tp in table order_d ##############
my $query_domain = qq{select * from order_d, order_m where DATE_SUB(domain_date,INTERVAL $queryresult_conf[0] DAY) <= DATE_SUB(curdate(),INTERVAL domain_period_yr YEAR) and order_m.order_id=order_d.order_id and order_m.user_id=$user_id and domain_reg="y" };
#print "query_domain = " . $query_domain . "<br>";
my $ret_mysql_domain = select_query($query_domain);
my $numrows_domain = $ret_mysql_domain->rows;
my @queryresult_domain;
############ end of getting all the registered domains whose days left from expiration=renew_mails_tp in table order_d ##############



The following then displays this to the user.

print "<br><br><font face=$normal_font_style size=$normal_font_size><b>Pending Domains</b></font>";
print "<table border=1 cellspacing='2' cellpadding='2' width='90%'>";
while (@queryresult_domain = $ret_mysql_domain->fetchrow_array())
{


print "<tr>";
my $dm = getDomain($queryresult_domain[3]);
my $newdate = &_unix_to_link_date($queryresult[10]);
my $renewdate = getRenewalDate($queryresult_domain[6]);
print "<td><font face=$normal_font_style size=$normal_font_size><a href=order_plan_hosting.pl?order_recur_id=$queryresult_domain[0]&order_section=recur_domain>$queryresult_domain[2]$dm</a></td>";
print "<td><font face=$normal_font_style size=$normal_font_size>$renewdate</td>";
print "</tr>";
}
print "</table>";


But the problem is $renewdate displays the correct date, but only of the last entry in the database and not the users domain.

I though that it would only work it out based on the $queryresult_domain but im obviously missing something to get it to display the date for the domain in question. Can someone tell me what?
Regards

Mark
http://www.host4.me.uk

No doubt i'll be back for more answers!
Quote Reply
Re: [mdj1] Adding x years to date and displaying In reply to
DOH!!

What an idiot!!

changed my($renewal_date) = @_; to my($domain_date) = @_;

added, where domain_date="$domain_date"

well, thats what you get for working at 4:45am!!!!

All working now!
Regards

Mark
http://www.host4.me.uk

No doubt i'll be back for more answers!