I have absolutely no idea how to do this and my current experiments just end up with the same old errors. It should be simple but i cannot get it to work. I'm not even sure which datatype to use in the db. Any help would be much appreciated
views:
8527answers:
5if you can execute a query from PHP then it should just be a matter of using 'getdate()' ;
update MyTable set MyColumn=getdate();
or
insert into MyTable (MyColumn) values (getdate());
edit: just realised you might mean that you want help actually executing a SQL Server query from PHP - that's not something I know anything about. Sorry if I misunderstood!
You just use the normal mechanism to execute your queries into SQL Server, and use what follows.
The current_timestamp function returns it
insert into table (creation_date) VALUES (current_timestamp)
Complete example
CREATE table timestamp_test (creation_timestamp datetime)
INSERT INTO timestamp_test (creation_timestamp) VALUES (current_timestamp)
SELECT * FROM timestamp_test
DROP TABLE timestamp_test
The column datatype should be datetime
You can either get the database to work out the date:
$sql = 'INSERT INTO tablename (fieldname) VALUES (getdate())';
or get PHP to work out the date
$sql = 'INSERT INTO tablename (fieldname) VALUES (\'' . date('Y-m-d H:i:s') . '\')';
then something like mssql_execute($sql);
but this depends on how you are connecting to your database
If you explain the error you are receiving (and post your insert or update code), it might make it easier to see what your problem is. One possible issue is that you must be inserting into a datetime field (or in 2008 you could use a date field as well). Occasionally people think that they can insert the current date into a timestamp field but even though the name of this data type seems as if it should be date related, this data type actaully has nothing to do with dates and times and cannot accept date data.