Jump to content

Time - Show days left to a timestamp


xwishmasterx

Recommended Posts

Hello

 

I have a timestamp formated as : "2011-10-20 12:37:21"

 

I need to show days left till this date (disregard the hours, minutes, seconds..), so I'll end up with 'there is "X" days left untill'

 

I really cannot figure you all this date/time stuff, but hopefully this is not to difficult  :-\

 

Anyone got a "quick" code for this?

 

 

Link to comment
https://forums.phpfreaks.com/topic/248660-time-show-days-left-to-a-timestamp/
Share on other sites

I created this function in a class I will be releasing soon (which I am excited about). But this subtracts 2 dates and gives you the number of days.

 

function datediff($start_date, $end_date, $exact = false){
if(!is_int($start_date)){
	if((bool)$exact)
		$start = strtotime($start_date);
	else
		$start = strtotime(date("Y-m-d", strtotime($start_date)));
}else{
	$start = $start_date;
}
if(!is_int($end_date)){
	if((bool)$exact)
		$end = strtotime($end_date);
	else
		$end = strtotime(date("Y-m-d", strtotime($end_date)));
}else{
	$end = $end_date;
}
return ($start - $end) / 60 / 60 / 24;
}

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.