Is it so difficult to use google with keywords search php+get+date+future .
From what I got from this search even me with no interest in PHP could make that part of the code work...
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
I have created a script for you to fiddle with and is below. The below script is a function where you can enter the number of days, months and years untill the future date and the function will return what that date is.
<?
function count_to_date($day,$month,$year)
{
$d=date(j)+$day;
$m=date(n)+$month;
$y=date(Y)+$year;
if ($d>31)
{
while ($d>31)
{
$d-=31;
$m+=1;
}
}
if ($m>12)
{
while ($m>12)
{
$m-=12;
$y+=1;
}
}
//below sets sequence: day/month/year
$r=$d.'/'.$m.'/'.$y;
return $r;
}
//below returns a future date (day/month/year)
echo count_to_date(3,0,0);
//a bit of theory
//count_to_date(number_of_days,number_of_months,number_of_years);
?>
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
Hi I really doubt whether this piece of code will work for every date.. It might not work with february date, leap years, and for months with months with 30 days like april..
Im providing you with some other code sample, that can work for most of the cases...
<?php
function count_to_date($curr_day,$curr_month,$curr_yr,$day,$month,$year)
{
$d=$curr_day+$day;
$m=$curr_month+$month;
$y=$curr_yr+$year;
if ($m>12)
{
$m-=12;
$y+=1;
}
$no_of_days=get_days_in_month($m,$y);
if ($d>$no_of_days)
{
$d-=$no_of_days;
$m+=1;
}
//below sets sequence: day/month/year
$r=$d.'/'.$m.'/'.$y;
return $r;
}
function leap_year($yr)
{
if($yr%4==0 || $yr%400==0)
return true;
else
return false;
}
function get_days_in_month($mnth_no,$yr)
{
switch($mnth_no)
{
case 1:
case 3:
case 5:
case 8:
case 10:
case 12:return 31;
break;
case 4:
case 6:
case 9:
case 11:return 30;
break;
case 2:if(leap_year($yr))
return 29;
else
return 28;
break;
}
}
//below returns a future date (day/month/year)
echo count_to_date(30,3,2007,1,0,1);
//a bit of theory
//count_to_date(number_of_days,number_of_months,number_of_years);
?>
sikka_varun
Junior Poster in Training
94 posts since Dec 2008
Reputation Points: 11
Solved Threads: 12