Jump to content

Archived

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

pocobueno1388

Quick easy date question.

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.

Share this post


Link to post
Share on other sites
you have to use the mktime() function.
try this:
[code]
$next_breed = date('Y/m/d', mktime(0, 0, 0, date('m'), date('d')+7, date('Y'));
[/code]

i aint sure though, i havnt used it very often.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
[quote author=Barand link=topic=110132.msg444609#msg444609 date=1159694357]
ps Best to store date as "Y-m-d", mysql's native format.
[/quote]

Best to store date as a UNIX timestamp: [url=http://php.net/time]time()

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Just [code]mysql_query("INSERT INTO table (the_time) VALUES(".time().");");[/code]

Share this post


Link to post
Share on other sites

×

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.