strtotime(); Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

strtotime(); Help

Post by icesolid »

If I have a field labeled 'date' in a database and I want to determine what date it will be 3 months from that 'date'.

In this example my 'date' field=2007-08-03 so I want to have PHP determine what 3 months from that date will be.

I have tried using strtotime but I am coming up with no solution.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What have you tried using strtotime()?
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post by icesolid »

Yes. Like this:

Code: Select all

<?php
echo date($row["date_ordered"], strtotime("+3 months")); 
?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
echo date('m/d/Y', strtotime($row["date_ordered"], '+3 months'));
?>
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post by icesolid »

That code just produces the same date_ordered. It does not change it to 3 months for the date_ordered.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry, had it wonky. Try this:

Code: Select all

<?php
echo date('m/d/Y', strtotime('+3 months', strtotime($row["date_ordered"])));
?>
User avatar
playgames
Forum Newbie
Posts: 22
Joined: Tue Sep 04, 2007 4:28 am

Post by playgames »

i think time() is the best type of data int

for index.for story.for database.

I'm use int(11) for it . as index.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Depending on the database you could actually do date math there and return what you want without needing to PHP it.
Post Reply