0

I have an online credit app with several fields that are month and year selections (time at address, hire date, etc) and want to not only display the results (March, 2011) that the analyst views, but also the length based on when the app was originally submitted. Unfortunately I can not change the structure of the dB, so instead need to change the output of the php, but have been unsuccessful.

The rows are: "ap_add8" = Month (January - December full text,) "ap_add9" = Year (2014) and "submitted" = the date the ap was submitted (2014-03-24.)

I've tried`

$Difference = abs(strtotime($row['ap_add9'].'-'.date("m", mktime(0, 0, 0, $row['ad_add8']))) - strtotime(date("Y").'-'.date(m))); 
$Years = floor($Difference / (365*60*60*24)); 
$Months = floor(($Difference - $Years * 365*60*60*24) / (30*60*60*24)); 
if ($Years !="0") {$Years = $Years.' years, ';} else {$Years = NULL;}
if ($Months !="0") {$Months = $Months.' months';} else {$Months = NULL;}`

To get it working based on todays date, but can't even get that working properly.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Brad Guy
  • 93
  • 1
  • 11
  • What's wrong with it? Have you tried solving it on a piece of paper first? It's a primary school-level math actually, isn't it? – zerkms Mar 24 '14 at 23:18
  • possible duplicate of [PHP Convert date to "blank" days/hours/seconds ago](http://stackoverflow.com/questions/18862055/php-convert-date-to-blank-days-hours-seconds-ago) – John Conde Mar 24 '14 at 23:19
  • Unless you're just trying to reinvent the wheel https://github.com/jimmiw/php-time-ago – Mattt Mar 24 '14 at 23:22

1 Answers1

0

Try getting the time today (time() - which returns a timestamp) then convert the date when the app started to a timestamp, then subtract. Then use some formatting with PHP's date format.

YouSer
  • 393
  • 3
  • 12