Jump to content

Recommended Posts

suppose i've one starting data(1/12/2013) and final date (26/12/2013). What i want is that to update the database with the difference between the dates every day...

 

means

start data  |  Final Data   |  Days Left
1/12/2012   | 26/12/2012    |  25                     <--------------     automatically done every day and updated in the database over writing the original values

 

Means after 2 days it will show  

start data  |  Final Data   |  Days Left
1/12/2012   | 26/12/2012    |  23 

Any help will be greately appreciated.....

Link to comment
https://forums.phpfreaks.com/topic/275780-automatically-insert-into-database/
Share on other sites

Don't store dates in mm/dd/yyyy format. You can't use the date/time functions on that to do date arithmetic. Use yyyy-mm-dd field type DATE.

 

And you don't  store the the "days left" If you have the two dates you calculate it whenever you need it.

You really only have to calculate between the current date, and the end date to find the number of days left.

 

 

SELECT DATEDIFF(Final Date,CURDATE()) AS days FROM table WHERE id = 1

 

Assuming of course that your columns are valid date type columns.

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.