Jump to content

Archived

This topic is now archived and is closed to further replies.

leeming

i feel so stupid asking a noob question about date()

Recommended Posts

i feel stupid asking this, but i seem to be in one of them state of minds where you cant think of the little simple things...

but how do i go about adding say 31 days to a date in this format: date("Y-m-d")

Share this post


Link to post
Share on other sites
$date = '2006-07-14';

$date31 = date ('Y-m-d', strtotime("+31 days $date"));

Share this post


Link to post
Share on other sites
Try this:
[code]<?php
$dt = date('Y-m-d');
$dt31 = date('Y-m-d,strtotime($dt . ' + 31 days'));
echo $dt . '<br>' . $dt31;
?>[/code]
or
[code]<?php
$one_day = 86400; // number of seconds in a day
$dt = '2006-07-20'; //arbitrary date
$dt31 = date('Y-m-d',strtotime($dt)+(86400 * 31)));
echo $dt . '<br>' . $dt31;
?>[/code]

Ken

Share this post


Link to post
Share on other sites
thanks.. i had justed started looking thru some SQL manuals. and ended up with this

[code]CURDATE() + INTERVAL ".$daynums." DAY[/code]

it worked for the INSERT but not an UPDATE.. will replace it with the above code. thanks

Share this post


Link to post
Share on other sites
That should work with either Insert or Update. Can you post the code that didn't work?

Ken

Share this post


Link to post
Share on other sites
trying to get this to work, bit over tired, and cant think stright...
[code]"update Premium set date_renew = ".date ('Y-m-d', strtotime("+31 days ".`date_renew`.""))." WHERE user='{$_POST[user]}'"[/code]

but the curdate code i tried before, i couldnt get to work.. some thing like..

[code]"update Premium set date_renew =`date_renew` + (CURDATE() + INTERVAL ".$daynums." DAY) WHERE user='{$_POST[user]}'""[/code]

~~ $daynums been a value of either 31 (month) or 365 (year)



~~edit 2..
fixed!

[code]"update Premium set date_renew =DATE_ADD(`date_renew`, INTERVAL $daynums DAY) WHERE user='{$_POST[user]}'"[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.