Razor42 Posted October 21, 2013 Share Posted October 21, 2013 Hi guys, I am currently creating a mod and I am having a few issues with time() and wondered if you’s could maybe help me out. Basically the users sets a time how long they want it to be (Minutes) here... Time (Minutes): <input type='text' name='time' value='Time....' /><br /> Then when storing the time in the DB I’m doing... $time = abs((int) $_POST['time']); $mtime = $time*60; //To turn the time from seconds to minutes $btime = time()+$mtime; Then when printing the time I am getting the time remaining as -202 (As an example) instead of something like 20 mintues? Any know why this is? Cheers. Quote Link to comment Share on other sites More sharing options...
HauntedDawg Posted October 21, 2013 Share Posted October 21, 2013 If you are storing it in a field as datetime type, you could do it via the query. mysqli_query('UPDATE `users` SET `time` = DATE_ADD(NOW(), INTERVAL '.intval($_POST['time']).' MINUTE) WHERE `id` = {ID}'); Quote Link to comment Share on other sites More sharing options...
Razor42 Posted October 21, 2013 Author Share Posted October 21, 2013 Unfortunately the mod is being done in MySQL not MySQL(i) Quote Link to comment Share on other sites More sharing options...
Razor42 Posted October 21, 2013 Author Share Posted October 21, 2013 The times have now gone to -7224 when being printed out. The times been stored as 1382345410. Quote Link to comment Share on other sites More sharing options...
HauntedDawg Posted October 21, 2013 Share Posted October 21, 2013 Unfortunately the mod is being done in MySQL not MySQL(i) No offense, but this is why most people get flamed. Did you try it in mysql? No. Did you try it in phpmyadmin? No. Will it work with mysql? Yes. Will it work in phpmyadmin? Yes. Why will it work? Because it still uses MySQL driver. Mysqli is a framework for mysql. How do i get it to work? Change mysqli_query to mysql_query. Quote Link to comment Share on other sites More sharing options...
Razor42 Posted October 21, 2013 Author Share Posted October 21, 2013 I don’t see why that would get me flamed? The reason people usually get flamed around here is because they come asking questions on how to do everything and expect everything given to them whereas I have actually done a lot of coding, I have contributed mods to the community and I do the majority of my work without having to ask a Question. I obviously don’t know much about mysqli which is why I thought it wouldn’t work. I will now go test it and see if it does work. - - - Updated - - - There is also the problem it’s not updating the users field it’s being inserted into the DB... The current query is... $db->query("INSERT INTO bounty (id, poster, targetn, target, money, time) VALUES ('', '{$userid}', '{$ft['username']}', '{$target}', '{$prize}', '{$btime}')"); So how would I go about doing that? Quote Link to comment Share on other sites More sharing options...
Razor42 Posted October 21, 2013 Author Share Posted October 21, 2013 I have resolved the initial error. Now I have another one... The time is currently displaying in seconds like 300 but I want it in minutes so it should be 5 right? How would I do this? Quote Link to comment Share on other sites More sharing options...
HauntedDawg Posted October 21, 2013 Share Posted October 21, 2013 I have resolved the initial error. Now I have another one... The time is currently displaying in seconds like 300 but I want it in minutes so it should be 5 right? How would I do this? If its displaying in seconds correctly. 300/60 = 5 $minutes = intval($database['seconds'] / 60); should do it. 1 Quote Link to comment Share on other sites More sharing options...
Razor42 Posted October 21, 2013 Author Share Posted October 21, 2013 Thank you for your help :). Quote Link to comment Share on other sites More sharing options...
Zettieee Posted October 21, 2013 Share Posted October 21, 2013 You are storing a time stamp. Time stamps count backwards from the time set. 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.