What I am trying to do is add a certain amount of time to the current time and then add that to the database but from some reason it only returns the hour time?

 $nowtime = date("Y-m-d H:i:s");

 if($time_selected==="wt-15")
 {
   $play_time = date('H:i:s', strtotime($nowtime . '+15 minutes'))+ " GMT ";
   $time_minus = "-15 minutes";
 } else if($time_selected==="wt-30") {
   $play_time = date('H:i:s', strtotime($nowtime .'+30 minutes'))+ " GMT ";
   $time_minus = "-30 minutes";
 } else if($time_selected==="wt-45") {
   $play_time = date('H:i:s', strtotime($nowtime .'+45 minutes'))+ " GMT ";
   $time_minus = "-45 minutes";
 } else { 
   $play_time = date('H:i:s', strtotime($nowtime .'+1 hour')) + " GMT ";
   $time_minus = "-1 hour";
 }

 $game_data =  array(
    'username_1' => $username,
    'amount' => $_POST['wamount'],
    'console' => $console,
    'pot' => $winner_pot,
    'time_selected' => $time_minus,
    'rules' => $_POST['gametype'],
    'time_game' => $play_time
);  

I echoed the query onto the page and this is the result

INSERT INTO `gsessions` ( `username_1`, `amount`, `console`, `pot`, `time_selected`,       `rules`, `time_game`) VALUES ('Aidan', '50', 'Xbox 360', '100', '-1 hour', 'gt-standard', '19')

19 being the hour it return, how can I return it in this format '19:15' for a VARCHAR field in the database?

有帮助吗?

解决方案

+ is not a concatenation operator in PHP; . is.

Change the lines that look like this:

$play_time = date('H:i:s', strtotime($nowtime .'+1 hour')) + " GMT ";

To this:

$play_time = date('H:i:s', strtotime($nowtime .'+1 hour')) . " GMT";

The problem was (in case you're curious) that it was treating it like you were doing integer addition. It typecast both strings as integers and then added them together.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top