Re: Date calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ron Piggott (PHP) wrote:

>I have one more date based question.
>
>I have a month field ( $month ) and a day field ( $day ) being submitted
>by a form.
>
>I have a third field to be used as a date reminder for the information
>which was submitted as part of the form.  It is a reminder to complete a
>task for the date was which was submitted as part of the form.  
>
>How do I calculate the $reminder date based on $month and $day and have
>it output in the YYYY-MM-DD format?  $reminder is the number of days
>before $month $day  (I want to use $reminder in a date format to SELECT
>records from a mySQL table)  This is why I am wanting put $reminder into
>a date format
>
>If $month was 6 and $day was 7 and $reminder was 6 then I would want the
>output to be 2007-06-01 --- We have already passed June 1st in 2006.
>However if $month was 11 then I would want the output to use this years
>date --- 2006-11-01
>
>Any suggestions?  
>
>Ron
>
>  
>
I think it would be easier to ask the user to enter his reminder in the
standard date format of yyyy-mm-dd and use a JavaScript date picker box
to prompt for it.  Anyway, you could do something like this:

$reminderStamp = strtotime("+{$addMonths} months",time());
$reminderStamp = strtoTime("+{$addDays} days",$reminderStamp);
$date = date("Y-m-d",$reminderStamp);

$date should have a string like yyyy-mm-dd that is $addMonths and
$addDays into the future.  I didn't test this.

Travis Doherty

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux