MySQL Query: Now + 7 days

  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

How do I put a value in a DATETIME field in a mysql database that is equal to seven days after the current date and time?

Regards,
Richard
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

UPDATE table_name SET date_field=FROM_DAYS(TO_DAYS(date_field) + 7) WHERE id_record=...

or

UPDATE table_name SET date_field=ADDDATE(date_field, INTERVAL 7 DAY) WHERE id_record=...
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

Hi
Thanks, but can't get it to work. What do I do to that query to ake it work with insert rather than update?

Regards,
Richard
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

I misunderstood your original question. Sorry:

INSERT INTO table (date_field) VALUES (ADDDATE(NOW(), INTERVAL 7 DAY));

Here, NOW() function returns current date.
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

Works perfect. To you, my good friend, 50 participation points.
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Thanks :)

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 161 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.