•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,989 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,217 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 364 | Replies: 2
![]() |
•
•
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 522
Reputation:
Rep Power: 2
Solved Threads: 53
•
•
Join Date: Sep 2007
Posts: 19
Reputation:
Rep Power: 1
Solved Threads: 1
hi....
I think you can use the following function to compare two dates.
function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
return $end_date - $start_date;
}
calling function is
$dformat shows the special character used to seperate date,month and year. it can be "-","/",etc.
$dateCmp=dateDiff("-",$date2,$date1);
Actually this function will return the number of days between $date1 and $date2. if the returned value is 0 then the two dates are equal. if it is greater than 0 then $date2 is greater than $date1 and so on.
Only one thing u have to notice is the date should be in MM-DD-YY format. For this you can use explode() function.
I think you can use the following function to compare two dates.
function dateDiff($dformat, $endDate, $beginDate)
{
$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);
return $end_date - $start_date;
}
calling function is
$dformat shows the special character used to seperate date,month and year. it can be "-","/",etc.
$dateCmp=dateDiff("-",$date2,$date1);
Actually this function will return the number of days between $date1 and $date2. if the returned value is 0 then the two dates are equal. if it is greater than 0 then $date2 is greater than $date1 and so on.
Only one thing u have to notice is the date should be in MM-DD-YY format. For this you can use explode() function.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
age amd avatar backup blue gene breach business chips daniweb data data protection database development dos economy energy enterprise europe government hacker hardware hp ibm ibm. news intel ibm it linux medicine memory microsoft news open source openoffice pc ps3 recession red hat russia security server sql sun supercomputer supercomputing survey technology trends ubuntu working x86
- coversion of dates from java(jsp) to sql (JSP)
- <B>I need your help!</B> (Visual Basic 4 / 5 / 6)
- date comparison (JSP)
- Script to compare dates? (Shell Scripting)
- Help on making and using Database in VB (Visual Basic 4 / 5 / 6)
- Generate User ID (PHP)
- A Guide for Finding Printer Support (Peripherals)
- checking to see if a coupon has expired (JSP)
- Winsock Multi-Client Servers (C++)
Other Threads in the PHP Forum
- Previous Thread: To expire login authentication in our site..
- Next Thread: paging


Linear Mode