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! Link to comment https://forums.phpfreaks.com/topic/107874-solved-mysql-datetime/ 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. Link to comment https://forums.phpfreaks.com/topic/107874-solved-mysql-datetime/#findComment-552977 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; Link to comment https://forums.phpfreaks.com/topic/107874-solved-mysql-datetime/#findComment-552990 Share on other sites More sharing options...
freeloader Posted May 29, 2008 Author Share Posted May 29, 2008 Thanks Link to comment https://forums.phpfreaks.com/topic/107874-solved-mysql-datetime/#findComment-552994 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? Link to comment https://forums.phpfreaks.com/topic/107874-solved-mysql-datetime/#findComment-553009 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 Link to comment https://forums.phpfreaks.com/topic/107874-solved-mysql-datetime/#findComment-553469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.