c-o-d-e Posted November 21, 2009 Share Posted November 21, 2009 I am creating an Expire Ban section in the database. I have setup this $bantime = date("d m y, G:i:s"); //setup time of expire $q = "INSERT INTO ".TBL_BANNED_USERS." VALUES ('$username', '$bantime', '$time', '$expire')"; The length of ban, is $time. How would I do $expire = $bantime + $time; $time value is in seconds. Would that be right. I know timestamps are best done in MySQL. I prefer it this way though. I like PHPFreaks new design. Link to comment https://forums.phpfreaks.com/topic/182425-how-would-i-do-datetime-add-seconds/ Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 Could you give us all the schema (structure - column types etc) of your database table? In PHP, you can get the current timestamp by using the function mktime() Then, you could add whatever seconds onto the current timestamp. Link to comment https://forums.phpfreaks.com/topic/182425-how-would-i-do-datetime-add-seconds/#findComment-962700 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 I just made it like this.. CREATE TABLE Banned ( Username varchar(40) primary key, BanDate text not null, Banlength varchar(50) null, ExpireDate varchar(50) null ); Link to comment https://forums.phpfreaks.com/topic/182425-how-would-i-do-datetime-add-seconds/#findComment-962703 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 You should be using the proper MySQL column types. Datetime is available to you. If you use the function mktime() properly, this will be pretty easy to accomplish. Also, your column Banlength is a bit redundant, seeing as you could get the ban length from the BanDate and ExpireDate columns, unless I'm mistaken otheriwse. Link to comment https://forums.phpfreaks.com/topic/182425-how-would-i-do-datetime-add-seconds/#findComment-962709 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 Well.. the banlength isn't needed in the database. It is however, needed to add onto the current timestamp, to make the ExpireDate. If I change the BanDate from text, to Datetime... What would I do for the rest, would mktime() be.. mktime(month day year hour:minute:second); I'm not sure. Then If I set that as a variable. How would I add the $time onto the mktime? Sorry, I'm not so understanding. Link to comment https://forums.phpfreaks.com/topic/182425-how-would-i-do-datetime-add-seconds/#findComment-962719 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 To get a datetime from PHP, use this: $datetime = date("Y-m-d H:i:s"); You can also use the mktime() function to specific a date in the future. Link to comment https://forums.phpfreaks.com/topic/182425-how-would-i-do-datetime-add-seconds/#findComment-962725 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 Ok, thanks. So.. from $datetime and $time How would I add them together to get the expire? Link to comment https://forums.phpfreaks.com/topic/182425-how-would-i-do-datetime-add-seconds/#findComment-962733 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 You can convert a datetime into a timestamp by doing this: $timestamp = strtotime($datetime); Link to comment https://forums.phpfreaks.com/topic/182425-how-would-i-do-datetime-add-seconds/#findComment-962738 Share on other sites More sharing options...
c-o-d-e Posted November 21, 2009 Author Share Posted November 21, 2009 Okay, but that doesn't explain how I'd get the expire date? Link to comment https://forums.phpfreaks.com/topic/182425-how-would-i-do-datetime-add-seconds/#findComment-962739 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.