MySQL Timestamp

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
giles
Forum Commoner
Posts: 34
Joined: Thu Sep 14, 2006 2:34 pm

MySQL Timestamp

Post by giles »

Hi,

I'm having trouble sending a PHP timestamp command to a MySQL database. I'm sending it as a normal query, but somethings not correct. Can you reccomment a simple tutorial or clarify what I should be doing?

Thanks
Giles
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

PHP doesn't have a function for making MySQL timestamps. If you're trying to update a MySQL timestamp column with a unix timestamp (as is generated by things like time() and mktime() ) it won't work because it's the wrong format.

If you want to set a timestamp column (or a date column, or a datetime column) to the time that you're carrying out an insert or update query you can set it to NOW() (eg "update table set myTimestampColumn = NOW() where id = 1;" ).
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

The MySQL commands FROM_UNIXTIME() and UNIX_TIMESTAMP() are nice for converting between UNIX & MySQL timestamps.

Your question is very unclear. What does 'sending' mean? What made you think something was incorrect?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
giles
Forum Commoner
Posts: 34
Joined: Thu Sep 14, 2006 2:34 pm

Post by giles »

pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Thanks for the response ... was getting a bit tied up over the form. For anybody who has an interest my working version is : 

[syntax="php"]mysql_query(" UPDATE session
SET
session_end = NOW()
WHERE 
session_id = '$session_id' ");
thanks for your time


pickle | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply