Finding Future Dates

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
Chinclub
Forum Newbie
Posts: 13
Joined: Sun Aug 31, 2008 7:33 am

Finding Future Dates

Post 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!
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Finding Future Dates

Post by josh »

use the date() function to format your timestamp. you could also just do date( 'formatstring', time() + ($days * 86400))
BETA
Forum Commoner
Posts: 47
Joined: Fri Jul 25, 2008 3:21 am

Re: Finding Future Dates

Post 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!
Post Reply