Link to home
Start Free TrialLog in
Avatar of syedasimmeesaq
syedasimmeesaqFlag for United States of America

asked on

date problem

I am using this to count the days till it expires

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;
}






$expiry_date = "07-11-2106";
$today = date('m-d-Y');

echo dateDiff("-",$expiry_date,$today); // # of days
echo "<br />";

which works fine. But if I change the $expiry_date = "2106-07-11" and $today = date('Y-m-d') it stops working. I need it to be in Y-m-d formate ..what can I do. Thanks
Avatar of Robin Uijt
Robin Uijt
Flag of Netherlands image

gregoriantojd() is expecting these parameters:

int gregoriantojd ( int $month , int $day , int $year )

so change the function to the one below and it will work in the other format:


function dateDiff($dformat, $endDate, $beginDate)
{
  $date_parts1=explode($dformat, $beginDate);
  $date_parts2=explode($dformat, $endDate);
  $start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
  $end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
  return $end_date - $start_date;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mahdii7
Mahdii7
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of syedasimmeesaq

ASKER

Works!