Jump to content


Photo

date/now **solved**


  • Please log in to reply
3 replies to this topic

#1 Noctagon

Noctagon
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 September 2006 - 12:36 AM

I am attempting to set up a variable so that it equals the current date and time so that I can send that to the database when an item is added so i know when it was added.

How do I do this?

Thanks :)

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 26 September 2006 - 12:49 AM

if you're wanting it in the typical SQL DATETIME format (YYYY-MM-DD HH:MM:SS), just use this:
<?php
$ts = date('Y-m-d h:i:s');
?>

however, if your SQL field is a DATETIME or other like datatype, why not just use the SQL function NOW()?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 26 September 2006 - 12:50 AM

Make sure you have a field for the time in your table, and then just do "UPDATE TABLE SET TIME=NOW() WHERE ..."

#4 Noctagon

Noctagon
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 September 2006 - 12:55 AM

if you're wanting it in the typical SQL DATETIME format (YYYY-MM-DD HH:MM:SS), just use this:

<?php
$ts = date('Y-m-d h:i:s');
?>


Thanks, that worked perfectly :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users