PHP Simple Date Calculations

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

user-7256

VIP Member
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
Close
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
Close
That's what I thought at first, but suppose the day is 2 and the other day is 19 ... but totally different months...
 
0
Close
0
Close
0
Close
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
Close
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
Close
0
Close
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
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back