Jump to content

Quick easy date question.


pocobueno1388

Recommended Posts

I am trying to add the current date + 7 days to the database whenever a user clicks a submit button, why won't this work?

[code]
$next_breed = date ('Y/m/d', strtotime ("U +7 days"));

mysql_query("UPDATE dog SET last_bred='$next_bred' WHERE dogID='$row3[dogID]'");
[/code]

It does absolutely nothing to the 0000-00-00 date in the database.
Link to comment
https://forums.phpfreaks.com/topic/22646-quick-easy-date-question/
Share on other sites

Typo!

$next_br[color=red]ee[/color]d = date ('Y/m/d', strtotime ("U +7 days"));

mysql_query("UPDATE dog SET last_bred='$next_br[color=red]e[/color]d' WHERE dogID='$row3[dogID]'");


ps Best to store date as "Y-m-d", mysql's native format.
So long as when you want to use MySQL's date/time functions you don't mind the additiona overhead of always converting it with FROM_UNIXTIME() first. e.g.
[code]
SELECT DATE_FORMAT(FROM_UNIXTIME(newtime), '%m-%d-%Y %H:%i') FROM tablename
[/code]

And you can always tell any users who might be executing their own SQL queries on the database that, with experience, they will soon get to recognise 1157137200 as  '2006-09-01 20:00' without any problem at all.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.