MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 30th, 2003, 11:53 AM
Neworld Neworld is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 2 Neworld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 sec
Reputation Power: 0
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:
 $date "2003-18-23"


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???

Reply With Quote
  #2  
Old February 24th, 2005, 03:42 PM
WMI WMI is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 WMI User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 28 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Store data in MYSQL TIMESTAMP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT