Jump to content

[SOLVED] Calculating Days between two dates


AXiSS

Recommended Posts

Hello, I need to calculate the numbers of days (only the number of days) between two days, one a variable $row['user_cp_name'] in the format MM/DD/YY, and another, the current time. I've tried a bunch of tutorials on the internet and none seem to work properly. Can I get some help?

if you don't have luck with that try


$chunk= $row['user_cp_name'];

$splice= explode("/", $chunk);

$date= gmmktime(0,0,0,$splice[0],$splice[1],$splice[2],0);

$diff= floor(time() - $date / 86400);

echo "Days since $chunk: $diff";

That gives me a number like: 1181002474

My bad I forgot to set the order for the math using brackets. Here you go.

 

<?php

$chunk= $row['user_cp_name'];

$splice= explode("/", $chunk);

$date= gmmktime(0,0,0,$splice[0],$splice[1],$splice[2],0);

$diff= floor((time() - $date) / 86400);

echo "Days since $chunk: $diff<br />";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.