Page 1 of 1

How to calculate countdown

Posted: Tue Jun 22, 2010 3:23 pm
by adsegzy
Hello friends,

I am building a website for vacancies, where people or companies come and post their vacancies. one of the fields in the form is for the person posting vacancy to select how long does he want the vacancy to be online may be 2,3,4,5 or 6 weeks from the day of posting. I know how to calculate number of days between 2 dates. but the problems is that assuming the poster wants the vacancy to be online for 2 weeks how will i do the count down to start counting from the day the vacancy is posted and be showing the number of days left for the vacancy when any visitor view the vacancy detail.

Thanks for always being there.

Re: How to calculate countdown

Posted: Tue Jun 22, 2010 3:41 pm
by AbraCadaver
You said "I know how to calculate number of days between 2 dates.", so calculate the number of days between the current date and the expire date (post date + 2 weeks) that you would store when the listing is posted.

Re: How to calculate countdown

Posted: Thu Jun 24, 2010 5:13 am
by adsegzy
AbraCadaver wrote:You said "I know how to calculate number of days between 2 dates.", so calculate the number of days between the current date and the expire date (post date + 2 weeks) that you would store when the listing is posted.
how do i put the syntax, assuming the date of posting is 24-06-2010 and the vacancies will expire in 2 weeks?

Re: How to calculate countdown

Posted: Thu Jun 24, 2010 6:16 am
by greyhoundcode
Something like this?

Code: Select all

// Get a time value for today
$today = time();

// How many days until expiry?
$daysToExpire = 14;

// Calculate time of expiry
$expiryDate = $today + ($daysToExpire * 86400);

// Convert to something human readable
echo date('j M Y', $expiryDate);

Re: How to calculate countdown

Posted: Fri Jun 25, 2010 2:56 am
by adsegzy
greyhoundcode wrote:Something like this?

Code: Select all

// Get a time value for today
$today = time();

// How many days until expiry?
$daysToExpire = 14;

// Calculate time of expiry
$expiryDate = $today + ($daysToExpire * 86400);

// Convert to something human readable
echo date('j M Y', $expiryDate);
Thanks greyhoundcode, i really appreciate that. more power to your elbow