subhomoy Posted March 17, 2013 Share Posted March 17, 2013 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..... Quote Link to comment https://forums.phpfreaks.com/topic/275780-automatically-insert-into-database/ Share on other sites More sharing options...
Barand Posted March 18, 2013 Share Posted March 18, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275780-automatically-insert-into-database/#findComment-1419216 Share on other sites More sharing options...
subhomoy Posted March 18, 2013 Author Share Posted March 18, 2013 okay but the starting date should be increased by 1 every day inorder to calculate the no of days left????? so that i can easily calculate the difference and can easily show to the user... Quote Link to comment https://forums.phpfreaks.com/topic/275780-automatically-insert-into-database/#findComment-1419237 Share on other sites More sharing options...
jcbones Posted March 18, 2013 Share Posted March 18, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275780-automatically-insert-into-database/#findComment-1419241 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.