Re:
Thanks a lot!!! I spent so time looking for this 2 lines!
X
August 6, 2008, 9:15 pm
Re:
Try this... take not though, date_parse requires PHP version 5.1.3 or higher.
/**
* Finds the difference in days between two calendar dates.
*
* @param Date $startDate
* @param Date $endDate
* @return Int
*/
function dateDiff($startDate, $endDate)
{
// Parse dates for conversion
$startArry = date_parse($startDate);
$endArry = date_parse($endDate);
// Convert dates to Julian Days
$start_date = gregoriantojd($startArry["month"], $startArry["day"], $startArry["year"]);
$end_date = gregoriantojd($endArry["month"], $endArry["day"], $endArry["year"]);
and I get a number that is not a whole number, it has several decimal places, how can i fix that?
use round
round(strtotime("2005-11-26")) / (60 * 60 * 24));
Selom
May 20, 2009, 1:38 pm
Re:
Very cool but how to get a date after adding 2 months to the current date? suppose i want to add 2 months to the $current_date ="Wednesday May 20, 2009". Thanks in advance
Tristavius
June 11, 2009, 4:39 am
Re: Selom
Using your example of 20th May 2009 + 2 months...
$d = date('Y-m-d', mktime(0,0,0,5+2,20,2009));
The mktime function is clever enough to understand what happens if, for example, you were to add 2 months to November 2000.... it will be clever enough to understand that 11+2 = 13 which it knows isn't a month and of course knows it should be january. In this example it will also be clever enough to add 1 to the years, giving a return date of January 2001. Same goes for if you were to add 7 days to May the 31st, it will correctly return June 7th.
The mktime function also accepts variables and other functions, I will use 2 examples below to demonstrate...
// Using Date Function To Add 2 To Current Date
$d = date('Y-m-d', mktime(0,0,0,date('m')+2,date('d'),date('Y')));
Finally, the 'Y-m-d' part can be changed to output a large number of configurations. The above returns [Full 4 Digit Year]-[Month With Leading Zero]-[Day With Leading Zero]. For a full list please see http://uk3.php.net/manual/en/function.date.php
Hope this helps!
Peter
June 20, 2009, 11:28 pm
Re:
Hi all, a need to the dates between two other dates, based on a var $jump, like the example:
So as a result i need to have the dates:
2009-04-10
2009-06-10
2009-08-10
2009-10-10
2009-12-10
2010-02-10
2010-04-10
Note that if i change the var $jump to 3 dates should be :
2009-04-10
2009-07-10
2009-10-10
2010-01-10
2010-04-10
How can i do this?
Thanks for help guys...
ashwani
June 26, 2009, 11:02 am
Re: date diff
first date diff tech.. is good .It works proper
sramesh
July 7, 2009, 8:38 pm
Re:
I was reading some tutorial to find no. of days between days and could not find it. this saved me a lot of time...
lcy
July 22, 2009, 11:51 am
Re: Why it doesn't work when using "d/m/y" format??
Hi! Can i ask for some help here....
I've tested the following script and it works.
However, when i use date in d/m/y format instead of m/d/y, thing goes wrong and the correct number of days can't be generated.
What can i do to get it right?
Need this in urgent...really hope to get some assistance here...Thanks in advance!
function dateDiff($startDate, $endDate)
{
// Parse dates for conversion
$startArry = date_parse($startDate);
$endArry = date_parse($endDate);
// Convert dates to Julian Days
$start_date = gregoriantojd($startArry["month"], $startArry["day"], $startArry["year"]);
$end_date = gregoriantojd($endArry["month"], $endArry["day"], $endArry["year"]);
Re: thanx
Thanx Alexandar,
this code works for me thanx very much
Hrithik
August 6, 2009, 12:37 pm
Re: thanx
Thnx Friends this code works for me also im very happy do the best
thxn again
Paul
November 7, 2009, 9:34 pm
date stuff
Hi all, i need to display some thing like:
"1 years, 7 months, and 25 days" as the diference of two date.
can anybody help???
TIA
Arunkumar P
November 16, 2009, 4:32 pm
Re:
nice work guys.. i found the solution.. thanks to all..
mugger
November 27, 2009, 2:08 am
Re: date diffs
I put your code examples between <php? and ?>, tried both print $days; and echo $days; , and see NO OUTPUT. Very puzzled.
mugger
November 27, 2009, 2:13 am
Re:
Oops. Should be <?php
Saravana
December 9, 2009, 1:31 pm
Re:
Veselin Stoilov,
Thanks a lot. Your code helped me to get the days between two dates.
Dadaso
December 23, 2009, 12:56 pm
Re: Saves a lot of time
first of all thanks a lot.saves a lot of time
ojie
December 28, 2009, 11:20 am
Re:
i want now number of the day form date 2009-12-31 ?
anybody help me ?
adi
January 22, 2010, 2:52 pm
i want to print
my query gvs this ans
name date
sandy 01/jan/2010
avi 02/jan/2010
sandy 02/jan/2010
sats 03/jan/2010
nil 03/jan/2010
sandy 03/jan/2010
avi 03/jan/2010
avi 04/jan/2010
sandy 05/jan/2010
Re: This will return days as array
function getDaysInBetween($start, $end) {
// Vars
$day = 86400; // Day in seconds
$format = 'Y-m-d'; // Output format (see PHP date funciton)
$sTime = strtotime($start); // Start as time
$eTime = strtotime($end); // End as time
$numDays = round(($eTime - $sTime) / $day) + 1;
$days = array();
// Get days
for ($d = 0; $d < $numDays; $d++) {
$days[] = date($format, ($sTime + ($d * $day)));
}
Re: can you fix it for me?
i want to calculate for two different date.
the start_date i name it c_date(state for $commencement_date). the second one is $today. the result i name the variable is $service_year. but somebody told me, that my wrong is in i state that one year as 365 days, but not really are( for leap year is 366 right) so, how can i fix this problem?
add two dates and months
I want to add two dates and add month.
Ranga Pathmasiri
June 23, 2010, 5:05 pm
Re:
This is a great job Jackson . Thanks Jackson
muhammad
August 19, 2010, 9:59 am
Re:
I have a different problem. I want to compute the week number between any two dates e.g 1Apr - 31Mar
how to compute the week number between them
thanks in advacne