Arty Ziff Posted December 3, 2010 Share Posted December 3, 2010 What is the best way to add a specific number of DAYS to a DATETIME value? Can it be done with MONTHS as well? Here's what I've come up with (is there a better way?): UPDATE some_table SET some_column = DATE_ADD(some_column,INTERVAL 30 DAY) WHERE ... Quote Link to comment https://forums.phpfreaks.com/topic/220599-adding-time-to-a-datetime-value/ Share on other sites More sharing options...
Pikachu2000 Posted December 3, 2010 Share Posted December 3, 2010 Assuming you're talking about getting the value from a MySQL database, MySQL's DATE_ADD() should be perfect. SELECT DATE_ADD( `timestamp` , INTERVAL 1 MONTH ) AS new_time FROM `table`; Quote Link to comment https://forums.phpfreaks.com/topic/220599-adding-time-to-a-datetime-value/#findComment-1142700 Share on other sites More sharing options...
requinix Posted December 3, 2010 Share Posted December 3, 2010 There's also the shorthand form of the same thing: `timestamp` + INTERVAL 1 MONTH Quote Link to comment https://forums.phpfreaks.com/topic/220599-adding-time-to-a-datetime-value/#findComment-1142718 Share on other sites More sharing options...
Arty Ziff Posted December 3, 2010 Author Share Posted December 3, 2010 There's also the shorthand form of the same thing: `timestamp` + INTERVAL 1 MONTH Yes... When using MONTH rather than DAY, MySQL knows the length of the months? Or is it some default segment of time such as 30 days? Quote Link to comment https://forums.phpfreaks.com/topic/220599-adding-time-to-a-datetime-value/#findComment-1142722 Share on other sites More sharing options...
fenway Posted December 5, 2010 Share Posted December 5, 2010 Neither -- it increments the month value by 1, nothing more. Quote Link to comment https://forums.phpfreaks.com/topic/220599-adding-time-to-a-datetime-value/#findComment-1143282 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.