Gossamer Forum
Home : General : Databases and SQL :

Inserting A Date into MySQL

Quote Reply
Inserting A Date into MySQL
Hi All,

Im having a problem, trying to do the following. I have a table which lists users domain names and when they registered them and how long for.

Now, when it comes to renewing the domains, it updates the date to the date in which they actually paid for the renewal, but i dont want this, i want it to add the ammount of years they have renewed for.

In the table i have domain_period_yr which is a numeric value of years and, domain_date.

What i want to happen is regardless of when they renew the domain it should just add the domain_period_yr to the date. i.e 2002-01-01 would become 2004-01-01 if the domain period was 2 years.

Any ideas how to achieve this would be much appreciated.
Regards

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

No doubt i'll be back for more answers!
Quote Reply
Re: [mdj1] Inserting A Date into MySQL In reply to
This is not a perl question, but anyway.

You will need to use the mySQL DATE_ADD() function, something like -
DATE_ADD(domain_date,domain_period_yr YEAR)
or you could use NOW() instead of domain_date which would give you 2 years from todays date, but I think in this case you need to use domain_date as the date reference.

Bob
http://totallyfreeads.com.au

Last edited by:

lanerj: Sep 21, 2003, 9:03 PM
Quote Reply
Re: [lanerj] Inserting A Date into MySQL In reply to
Sorry, i meant to put it in the databases forum, could someone move it?
Regards

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

No doubt i'll be back for more answers!
Quote Reply
Re: [mdj1] Inserting A Date into MySQL In reply to
OK, i tried what you suggested but i get an internal serer error.

Here is the line that puts the info in the database.

Code:
my $query_order_d = qq{update order_d set domain_period_yr=trim("$domain_period"),domain_amount=trim("$domain_price"),domain_date=curdate() where order_recur_id=$order_recur_id };
Regards

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

No doubt i'll be back for more answers!
Quote Reply
Re: [mdj1] Inserting A Date into MySQL In reply to
Moved.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [mdj1] Inserting A Date into MySQL In reply to
Sorry,
The DATE_ADD() format was incorrect.
Try this -
DATE_ADD(CURDATE(), INTERVAL "$domain_period" YEAR);
That will add $domain_period years to CURDATE().
You can also use an existing date field instead of CURDATE(). MySQL is very flexible when it comes to date manipulation.
For the DATE_ADD function see -
http://www.mysql.com/...nctions.html#IDX1319

Bob
http://totallyfreeads.com.au
Quote Reply
Re: [lanerj] Inserting A Date into MySQL In reply to
Thanks guys,

I finally got this to work!
Regards

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

No doubt i'll be back for more answers!