Page 1 of 1
strtotime(); Help
Posted: Tue Sep 04, 2007 10:44 am
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.
Posted: Tue Sep 04, 2007 10:47 am
by RobertGonzalez
What have you tried using
strtotime()?
Posted: Tue Sep 04, 2007 10:49 am
by icesolid
Yes. Like this:
Code: Select all
<?php
echo date($row["date_ordered"], strtotime("+3 months"));
?>
Posted: Tue Sep 04, 2007 10:55 am
by RobertGonzalez
Code: Select all
<?php
echo date('m/d/Y', strtotime($row["date_ordered"], '+3 months'));
?>
Posted: Tue Sep 04, 2007 10:57 am
by icesolid
That code just produces the same date_ordered. It does not change it to 3 months for the date_ordered.
Posted: Tue Sep 04, 2007 11:10 am
by RobertGonzalez
Sorry, had it wonky. Try this:
Code: Select all
<?php
echo date('m/d/Y', strtotime('+3 months', strtotime($row["date_ordered"])));
?>
Posted: Tue Sep 04, 2007 9:15 pm
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.
Posted: Wed Sep 05, 2007 10:28 am
by RobertGonzalez
Depending on the database you could actually do date math there and return what you want without needing to PHP it.