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
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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.