| | |
Getting Future Date
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
I don't know how to explain this correctly but just some sample for you guys so that you can really get what Im trying to say.
Today is November 28, 2008
3 days from now is December 1,2008
Im looking for a php code, which can give me the exact date giving the number of days interval prior to the current date.
I've been looking for a thread which can solve or even give a hint on how to solve this one but I found none.
Today is November 28, 2008
3 days from now is December 1,2008
Im looking for a php code, which can give me the exact date giving the number of days interval prior to the current date.
I've been looking for a thread which can solve or even give a hint on how to solve this one but I found none.
:: xarz ::
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...
From what I got from this search even me with no interest in PHP could make that part of the code work...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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.
php Syntax (Toggle Plain Text)
<? 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); ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
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...
Im providing you with some other code sample, that can work for most of the cases...
PHP Syntax (Toggle Plain Text)
<?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 and cwarn23
thanks alot for the codes..
I make some modifications to fit my need from your work guys.
basically the changes are adding a parameter so that I can choose what date I want to start counting off.
Here is the outcome:
can be called by
and the output will be
2007-07-06 06:00:00
anyways,thanks alot for the suggestions and the sample code.. i really appreciate it.
thanks alot for the codes..
I make some modifications to fit my need from your work guys.
basically the changes are adding a parameter so that I can choose what date I want to start counting off.
Here is the outcome:
php Syntax (Toggle Plain Text)
function count_to_date($sqldate,$day,$month,$year) { $d=substr($sqldate,8,2); $m=substr($sqldate,5,2); $y=substr($sqldate,0,4); $h=substr($sqldate,11,2); $min=substr($sqldate,14,2); $d=intval($d)+$day; $m=intval($m)+$month; $y=intval($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 if($d<10) $d='0'.$d; if($m<10) $m='0'.$m; $r=$y.'-'.$m.'-'.$d.' '.$h.':'.$min.':00'; return $r; }
can be called by
PHP Syntax (Toggle Plain Text)
echo count_to_date("2007-07-01 06:00:00",5,0,0);
and the output will be
2007-07-06 06:00:00
anyways,thanks alot for the suggestions and the sample code.. i really appreciate it.
Last edited by xarz; Dec 2nd, 2008 at 10:29 pm.
:: xarz ::
![]() |
Similar Threads
- Date verification (VB.NET)
- php date function (PHP)
- help me to read my data file:(( (C)
- Date Formatting Calculations!!! (ASP.NET)
- Need Help on getting my pc to a previous date (Windows NT / 2000 / XP)
- Date type problem JSP, mySQL (Java)
- Convert an OEM XP Home FAT to NTFS (Windows NT / 2000 / XP)
- Countdown (Java)
- HijackThis (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: please help
- Next Thread: Passing form data to default file of a directory
| Thread Tools | Search this Thread |
address apache api array auto autoincrement beginner binary broken cache cakephp checkbox class cms code cron curl customizableitems database date dehasher display dynamic echo email error errorlog external file files folder form format forms forum function functions gc_maxlifetime google headmethod host href htaccess html image include incode insert ip javascript joomla limit link login mail malfunctioning masterthesis menu method mlm multiple mysql oop parsing paypal pdf php phpmysql popup problem query question radio random recursion remote script search select server sessions sms source space sql support! survey syntax system table trouble tutorial update upload url validator variable video web youtube






