Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 13 July 2006 - 11:37 PM

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")
Im not perfect ;) lol

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 14 July 2006 - 12:22 AM

$date = '2006-07-14';

$date31 = date ('Y-m-d', strtotime("+31 days $date"));
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 14 July 2006 - 12:25 AM

Try this:
<?php
$dt = date('Y-m-d');
$dt31 = date('Y-m-d,strtotime($dt . ' + 31 days'));
echo $dt . '<br>' . $dt31;
?>
or
<?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;
?>

Ken

#4 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 14 July 2006 - 12:35 AM

thanks.. i had justed started looking thru some SQL manuals. and ended up with this

CURDATE() + INTERVAL ".$daynums." DAY

it worked for the INSERT but not an UPDATE.. will replace it with the above code. thanks
Im not perfect ;) lol

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 14 July 2006 - 12:37 AM

That should work with either Insert or Update. Can you post the code that didn't work?

Ken

#6 leeming

leeming
  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 14 July 2006 - 12:53 AM

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

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

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

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



~~edit 2..
fixed!

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

Im not perfect ;) lol




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users