Jump to content

automatically insert into database


subhomoy

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.

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.