Jump to content

Create new date from max date


Terminaxx
 Share

Recommended Posts

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

Link to comment
Share on other sites

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 by Terminaxx
Link to comment
Share on other sites

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 by ginerjm
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.