Jump to content


Photo

Quick easy date question.


  • Please log in to reply
5 replies to this topic

#1 pocobueno1388

pocobueno1388
  • Members
  • PipPipPip
  • Advanced Member
  • 3,369 posts
  • LocationPalm Beach, Florida

Posted 01 October 2006 - 07:51 AM

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?

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

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

It does absolutely nothing to the 0000-00-00 date in the database.

#2 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 01 October 2006 - 08:56 AM

you have to use the mktime() function.
try this:
$next_breed = date('Y/m/d', mktime(0, 0, 0, date('m'), date('d')+7, date('Y'));

i aint sure though, i havnt used it very often.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 October 2006 - 09:19 AM

Typo!

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

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


ps Best to store date as "Y-m-d", mysql's native format.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 01 October 2006 - 09:25 AM

ps Best to store date as "Y-m-d", mysql's native format.


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

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 October 2006 - 10:50 AM

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.
SELECT DATE_FORMAT(FROM_UNIXTIME(newtime), '%m-%d-%Y %H:%i') FROM tablename

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.

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 01 October 2006 - 03:56 PM

Just
mysql_query("INSERT INTO table (the_time) VALUES(".time().");");





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users