Dynadot โ€” .com Registration $8.99

PHP Simple Date Calculations

Spaceship Spaceship
Watch
Impact
111
Hey,

I have date stored in this format:

MM-DD-YYYY

Actually I have 2, but they're different, just in the same format.

I want to know the difference in DAYS between them. (e.g. 30 days apart, 20 days, are the two differences I really want...)

Any help appreciated!

-Matt
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Explode Method
PHP:
$dos = explode("-", $date);
$dos2 = explode("-", $date2);

$dbetween = $dos['2']-$dos2['2'];

List & Split Method
PHP:
list($month, $day, $year) = split('[-]', $date);
list($month2, $day2, $year2) = split('[-]', $date2);

$dbetween = $day-$day2;

iNod.
 
0
•••
That's what I thought at first, but suppose the day is 2 and the other day is 19 ... but totally different months...
 
0
•••
0
•••
0
•••
I believe DATEDIFF is available in MySQL 4.1.1 and above.
If you are unsure which version you are running check with this command:
Code:
SELECT VERSION()
 
0
•••
SDS - can you CONFIRM that I can use that function with 4.1.1? If so and it works I'll hand over some NP$.
 
0
•••
0
•••
PHP method:

PHP:
<?
	$t = explode("-","08-28-1979");
	$date1 = strtotime($t[2].'-'.$t[1].'-'.$t[0]);

	$t = explode("-","08-28-1980");
	$date2 = strtotime($t[2].'-'.$t[1].'-'.$t[0]);

	$diff = ($date2-$date1)/86400;
?>
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back