If you are working with a timestamp in some other format, this works
well:

        $ts = date("Y-m-d H:i:s",strtotime($sring_with_timestamp));

If you want to create a timestamp at the execution time, this works
well:

        $ts = date("Y-m-d H:i:s");

Both will generate mysql compatiable date/time stamps.
Then do the sql insert/update of your record.

-----Original Message-----
From: Chris Dowell [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 21, 2004 10:00 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] inserting timestamp into mysql field


Not really a MySQL question - the answer happens to be MySQL, but the 
question asks how to do it in PHP

This might still be necessary if the OP is using something like 
DB_DataObject, as you can't really use NOW() in that situation

Try strftime [ http://uk.php.net/strftime - RTFM :) ] - a good format 
string would be "%Y-%m-%d %H:%M:%S" which will produce 0000-00-00
00:00:00

Marek Kilimajer wrote:

> [EMAIL PROTECTED] wrote:
> 
>> Subject: inserting timestamp into mysql field
>>
>> hi there,
>>
>> i need to insert a current timestamp into a mysql field when a form
is 
>> posted.
>> can anyone suggest a simple way of doing this? i would like to set a 
>> variable
>> in my php script to add into the insert statement. it needs to be in
the
>> format 00-00-00 00:00:00.
> 
> 
> insert table set ......, date_added = NOW()
> 
> mysql question by the way...
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to