Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Code Newbie > Submit Tutorials > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 02-16-2003, 11:59 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
Converting MySQL Timestamp to a Unix Timestamp

If you use MySQL and have a field defined as 'timestamp', then you may find problems when trying to format the time when using PHP. This tutorial will instruct you how to convert a MySQL timestamp into a Unix timestamp directly from the query.

For this example we will use a table named "EXAMPLE_TABLE" and a field named "TIME". If you try to query the MySQL database and format the TIME result in PHP, you may find that the date is completely wrong. This is because you must request the TIME field in a Unix Format. Below is an example how to pull the TIME field out of the MySQL database and format it with PHP.
PHP Code:
<?
$result
=mysql_query("SELECT UNIX_TIMESTAMP(TIME) AS FORMATED_TIME FROM EXAMPLE_TABLE");
$FORMATED_TIME=mysql_result($result,0,"FORMATED_TIME");

$date=date("m-d-Y H:i:sa",$FORMATED_TIME);

echo 
"$date";
?>
This will print to the browser something like this:
Code:
4-20-2002 6:30:21am
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
and on to mysql .. sde Linux / BSD / OS X 2 01-18-2003 07:39 PM


All times are GMT -8. The time now is 03:59 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting