PHP - How to calculate countdown - Asked By Olusegun A. on 24-Jun-10 06:30 AM

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.
Ramendra Kumar replied to Olusegun A. on 24-Jun-10 06:36 AM

just do one thing,at the time of posting get the date time and then add whatever poster wants, means if poster wants to show this post for 2 weeks then add 14 days in current date and save them in the data base, Now  on page load check that date time is he greater than or equal to  today's  date then that post will be visible , else that won't visit to any one's

samjayander thiagarajan replied to Olusegun A. on 24-Jun-10 06:39 AM

Instead of counting the number of days each time you fetch the record, you can go like this.

You can have a extra field named "ExpiryDate" and on entry, you can calculate the expiry date based on the number of days specified and update the Expiry date with the value.

Each time you fetch the records, you can get the records whose expiry days are lesser that current date.

So you can get the vaccancies which are not expired by using SQL statements like,
where expiryDate < CurrenntDate

numberofdatesLeft = expirydate - currentDate

Santhosh N replied to Olusegun A. on 24-Jun-10 06:47 AM

To accomplish this easily, incorporate the DB table to contain the following min columns

DatePosted --> to contain the date the vacancy is posted

DateExpiry  --> Date till vacancy presents

Duration   --> To also store how long the post needs to be made available, not required but better to have

Olusegun A. replied to Olusegun A. on 01-Jul-10 03:47 AM
Thank you all i really appreciate your assistance. more power to your elbow.