Page 1 of 1

Finding Future Dates

Posted: Sun Sep 14, 2008 10:07 am
by Chinclub
I'm trying to write a script that will randomly pick a date 1-5 days from today that will eventually be updated into the mysql in a certain field which is set as DATE so I need it to read out as YYYY-mm-dd. I haven't done a lot with date and in my research have found mktime code and CURDATE() but I can't get either to work right in finding a future date. I can echo it correctly but not have it update=mysql correctly. I was playing around with something like this:

Code: Select all

$twodays = mktime(0, 0, 0, date("Y"), date("m"), date("d")+2);

But its not working so I must be in the completely wrong direction. Can someone point me toward the correct code I should be using to find a future day that can then be updated into the database in a DATE feild. If you can point me in the right direction I can search for some tutorials.

Thanks!

Re: Finding Future Dates

Posted: Sun Sep 14, 2008 10:57 am
by josh
use the date() function to format your timestamp. you could also just do date( 'formatstring', time() + ($days * 86400))

Re: Finding Future Dates

Posted: Sun Sep 14, 2008 3:21 pm
by BETA
Have you tried the strtodate function?
example:

Code: Select all

<?php
$dplusplus = strtotime("+2 day");
$dd = date("Y m d", $dplusplus);
echo $dd;
?>
will print out the current date plus two days :)
hope that helps!