Jump to content

Subtracting dates to get "days left"?


virtuexru

Recommended Posts

OK. Quick dilemma here.

 

I have two dates. One is when a vehicle is "added" and one when it should be "deleted".

 

So it would look like this:

 

Added date: 2008-10-29

Deleted date: 2008-11-03

 

So I'm trying to do a psuedo "deleted - added = days left" but it doesn't work like that obviously.

 

Should I strip the "-" and try subtraction? But that won't always be accurate. What do you guys suggest?

Link to comment
https://forums.phpfreaks.com/topic/130613-subtracting-dates-to-get-days-left/
Share on other sites

Nevermind, figured it out:

 

	$added   = strtotime($row['_added']);
	$launch  = strtotime($row['_launch']);

                // show the date it goes off in a readable format
	$dateoff = date('M d, Y', strtotime($row['_launch']));

	$left    = ($launch - $added);

                // rounds it to days instead of seconds
	$left    = round($left / 86400);

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.