freeloader Posted May 29, 2008 Share Posted May 29, 2008 Hi guys, Just a quick question I couldn't find on google. I have a datetime field storing a date and time like this: 2008-05-29 23:15:00. If I need to set the datetime 5 hrs further, is it possible to use the update function somehow? Like this: UPDATE mytable SET datefield = 'NOW() + 5hrs' Thanks in advance! Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 29, 2008 Share Posted May 29, 2008 Look at the DATE_ADD or ADDDATE mysql functions. Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 29, 2008 Share Posted May 29, 2008 DarkWater has a good suggestion, but it turns out, you don't even have to incorporate those: UPDATE mytable SET datefield = NOW() + INTERVAL 5 HOUR; Quote Link to comment Share on other sites More sharing options...
freeloader Posted May 29, 2008 Author Share Posted May 29, 2008 Thanks Quote Link to comment Share on other sites More sharing options...
freeloader Posted May 29, 2008 Author Share Posted May 29, 2008 Additional question: what if I want to add 5 hours and 1 minute? Or 1 day and 5 minutes? Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 30, 2008 Share Posted May 30, 2008 Additional question: what if I want to add 5 hours and 1 minute? Or 1 day and 5 minutes? I believe you could just create an arithmetic operation: UPDATE mytable SET datefield = (NOW() + INTERVAL 1 DAY + INTERVAL 5 MINUTE); Try it out and see Quote Link to comment 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.