php - Returning months difference as integer -


i trying return month difference integer , call if table column. code:

function eta($arrivaldate, $pattern = 'mysql'){   $patterns = array(     'eu'    => 'd/m/y',     'mysql' => 'y-m-d',     'us'    => 'm/d/y', );     $currentdate = date("y-m-d");      $arrivaldate = $variants_data['arrivaldate'];      $diff = $arrivaldate->diff($currentdate);      return $diff->y;  } 

the call with

<td>'.$_get['eta'].'</td> 

but there nothing returned, doing wrong here?

you can want in simpler approach using datetime object in php:

function eta($arrivaldate){     $currentdate = new datetime();     $arrivaldate = new datetime($arrivaldate);     $interval    = $currentdate->diff($arrivaldate);     return $interval->format('%m'); } 

see working example: http://3v4l.org/ulpqo

if don't pass in appropriate format $arrivaldate exception thrown, need wrap call in try/catch.

see datetime interval format more on return value.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -