Terminaxx Posted November 2, 2017 Share Posted November 2, 2017 Hey guys, first I want to apologize for my English and hope you still understand what i am trying to do. So i got a table with many timestamps in it - like this: 2017-11-04 00:00:00 I want to get the object with the highest timestamp (the farest day) and add exactly one day to it and add it to the table. Like if we say the above timestamp was the highest, the next one should be like this: 2017-11-05 00:00:00 How can i do this and add it to the table without any error? Thanks for any help Quote Link to comment https://forums.phpfreaks.com/topic/305531-create-new-date-from-max-date/ Share on other sites More sharing options...
ginerjm Posted November 2, 2017 Share Posted November 2, 2017 So many questions can be answered by looking in the Official PHP Manual. Too bad you didn't try that first..... http://php.net/manual/en/datetime.add.php Quote Link to comment https://forums.phpfreaks.com/topic/305531-create-new-date-from-max-date/#findComment-1553321 Share on other sites More sharing options...
Terminaxx Posted November 2, 2017 Author Share Posted November 2, 2017 (edited) The main problem is, how to get the timestamp out of the table, add 1 day and put it as a new column in. Therefore I got problems with representing the timestamp in the right order. I tried this: $highdate = mysqli_fetch_object(mysqli_query($con, "SELECT * FROM auctions ORDER BY yourdate DESC LIMIT 1"))->yourdate; $date = date_create('$highdate'); date_add($date, date_interval_create_from_date_string('2 days')); (tried it here with 2 days) but in the table i got it in this format: 0000-00-00 00:00:00 Edited November 2, 2017 by Terminaxx Quote Link to comment https://forums.phpfreaks.com/topic/305531-create-new-date-from-max-date/#findComment-1553324 Share on other sites More sharing options...
ginerjm Posted November 2, 2017 Share Posted November 2, 2017 (edited) Your code is so flawed in your example that you have WAY more problems that a little date math. Why are you fetching an object? You originally showed us a date value that looked just like what one gets from a query. Why make it part of an object? It was perfect as it was. Make a date value out of it. Read the Manual and look at the examples for date() Then look at the reference I gave you. Then do some more reading on how to enclose a php variable in quotes properly. Edited November 2, 2017 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/305531-create-new-date-from-max-date/#findComment-1553326 Share on other sites More sharing options...
Barand Posted November 2, 2017 Share Posted November 2, 2017 $result = $pdo->query("SELECT MAX(yourdate) as date FROM auctions"); $date = new dateTime($result->fetchColumn()); $date->add(new dateInterval('P1D')); echo $date->format('Y-m-d H:i:s'); Quote Link to comment https://forums.phpfreaks.com/topic/305531-create-new-date-from-max-date/#findComment-1553330 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.