adzie Posted April 17, 2009 Share Posted April 17, 2009 Hello guys sounds like a simple question but... i want to update a number in the database so something like below where hours is the existing data. At the moment all I get is the 200 not the original plus 200 UPDATE user SET hours = 'hours' + '200' WHERE user_id = 1 Quote Link to comment https://forums.phpfreaks.com/topic/154560-add-numbers/ Share on other sites More sharing options...
Philip Posted April 17, 2009 Share Posted April 17, 2009 UPDATE `user` SET `hours`=`hours`+200 WHERE `user_id` = 1 You don't need the quotes around the col name like that Quote Link to comment https://forums.phpfreaks.com/topic/154560-add-numbers/#findComment-812728 Share on other sites More sharing options...
adzie Posted April 17, 2009 Author Share Posted April 17, 2009 Thanks that brilliant, what if I want to add say time? say 200:14:12 ? Quote Link to comment https://forums.phpfreaks.com/topic/154560-add-numbers/#findComment-812733 Share on other sites More sharing options...
Philip Posted April 17, 2009 Share Posted April 17, 2009 Use the datetime functions: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html Quote Link to comment https://forums.phpfreaks.com/topic/154560-add-numbers/#findComment-812735 Share on other sites More sharing options...
adzie Posted April 17, 2009 Author Share Posted April 17, 2009 thanks kingphillip The trouble is if the hours are over 838:59:59 i couldnt get a time function to work hours = ADDTIME(`hours`,'$time') Quote Link to comment https://forums.phpfreaks.com/topic/154560-add-numbers/#findComment-812738 Share on other sites More sharing options...
Philip Posted April 17, 2009 Share Posted April 17, 2009 I haven't tried it, but I've heard that using TIMESTAMPADD() works sometimes. I'll see if I can pull up that article Quote Link to comment https://forums.phpfreaks.com/topic/154560-add-numbers/#findComment-812744 Share on other sites More sharing options...
adzie Posted April 17, 2009 Author Share Posted April 17, 2009 cheers I found an example and tried that but couldnt get a result Quote Link to comment https://forums.phpfreaks.com/topic/154560-add-numbers/#findComment-812753 Share on other sites More sharing options...
adzie Posted April 17, 2009 Author Share Posted April 17, 2009 i've added the time as a varchar field but cant add 10:10:10 Quote Link to comment https://forums.phpfreaks.com/topic/154560-add-numbers/#findComment-812770 Share on other sites More sharing options...
fenway Posted April 17, 2009 Share Posted April 17, 2009 What's wrong with a good ol' INT? Quote Link to comment https://forums.phpfreaks.com/topic/154560-add-numbers/#findComment-812779 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.