|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Store data in MYSQL TIMESTAMP
Hi to Everyone!!!
I'm trying to store data in a table but in TIMESTAMP The var I recive is the date and comes like this: PHP Code:
I would like to see an example of an insert query and of a select query to see how is the correct way. Can someone help me??? |
|
#2
|
|||
|
|||
|
Here's an example of an insert query:
mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT INTO mytable VALUES (' ','$otherData',NOW())"; mysql_query($query); mysql_close(); In this case, NOW() will insert a MySQL timestamp into the final field (which in this case is called dateSubmitted) of a table called "mytable." To do your Select query you can use the following in addition to your normal queries: $result=mysql_query("SELECT UNIX_TIMESTAMP(dateSubmitted) AS FORMATED_TIME FROM mytable"); $FORMATED_TIME=mysql_result($result,0,"FORMATED_TIME"); $date=date("F d, Y, H:i:s A",$FORMATED_TIME); Then for your results you would use: echo "$date"; Assuming the timestamp was "20050224124736" the date would convert to read as follows: February 24, 2005, 12:47:36 PM You could adjust this result by changing the format of the date function using the various date expressions provided for with PHP. I hope this helps you. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Store data in MYSQL TIMESTAMP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|