Hello..

I want to compare my database date with current system date and i can do some oprations by that..

Wating ...

Shanti

Recommended Answers

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. …

Jump to Post

All 4 Replies

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.

Thank you DITTYY for your quick response...

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'd recommend using the large format date in php - $date2 = date("m-d-Y"), as opposed to the small "y", (which produces "09" as compared to 2009).

thank you...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.