•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,528 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,781 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1969 | Replies: 10 | Solved
![]() |
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
$query="Select MINUTE(date),DAY(date),HOUR(date),
MONTH(date),YEAR(date),WEEK(date),
SECOND(date) from table"
the "date" is the date field of your table.
Try this.thanks.
then combine whatever field of time you want in the output.
MONTH(date),YEAR(date),WEEK(date),
SECOND(date) from table"
the "date" is the date field of your table.
Try this.thanks.
then combine whatever field of time you want in the output.
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
(new php coder here)
So, if I have something like this
How would I identify each column?
Normally I would use this: echo $row['column'];
But not sure what to do with the date functions.
Thanks!
So, if I have something like this
@mysql_query('SELECT DAY(createdTime),MONTH(createdTime),YEAR(createdTime),title FROM...How would I identify each column?
Normally I would use this: echo $row['column'];
But not sure what to do with the date functions.
Thanks!
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
$result = @mysql_query('SELECT createdTime FROM artman_article ');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each rec in a paragraph
while ($row = mysql_fetch_array($result)) {
echo $row[date('Y m d',strtotime($createdTime))];
}After some searching here, it looks like the date() and strtotime()
functions might do the trick.
See above.
But-- Apparently the syntax is incorrect (?). There are no results.
Thanks again.
Last edited by jmueller0823 : Oct 2nd, 2007 at 1:07 pm.
•
•
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 181
Reputation:
Rep Power: 3
Solved Threads: 10
•
•
•
•
I just finished a php MySQL query. Everything is great, except
the date column doesn't format correctly.
The date output looks like this: 1175114705
The date column prints from: echo $row['createdTime'];
Ideas? Thanks.
It seems that your timestamp is in unix format. In order to convert it to a humanly readble one there is a function in php called unixtojd(unixdate);
So if it is a unix date, then this code should do the trick:
[php]
$select = 'select timestamp from mydb.mytable';
$rslt = @mysql_query($select);
if (!$rslt)
{
echo 'Ooooppss:'.mysql_error();
}
else {
$unixdate = mysql_fetch_array($rslt);
$normaldate = unixtojd($unixdate['timestamp']);
echo $normaldate;
}
[/php]
Tell us if it works...Note php should be 4 and above
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
I miss my mind the most...."
Mark Twain
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Thanks.
(PHP Version 4.4.7)
Okay. Tried this:
No results. No errors. Ideas?
(The basic code structure is okay i.e. using different columns in Select,
the code will produce results. The above is just an excerpt from the script.)
(PHP Version 4.4.7)
Okay. Tried this:
<?php
$result = @mysql_query('SELECT createdTime FROM artman_article');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display each rec
$unixdate= mysql_fetch_array($result);
$normaldate = unixtojd($unixdate['createdTime']);
echo $normaldate;
}
?>(The basic code structure is okay i.e. using different columns in Select,
the code will produce results. The above is just an excerpt from the script.)
Last edited by jmueller0823 : Oct 2nd, 2007 at 2:54 pm.
•
•
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 181
Reputation:
Rep Power: 3
Solved Threads: 10
•
•
•
•
Thanks.
(PHP Version 4.4.7)
Okay. Tried this:No results. No errors. Ideas?<?php $result = @mysql_query('SELECT createdTime FROM artman_article'); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } // Display each rec $unixdate= mysql_fetch_array($result); $normaldate = unixtojd($unixdate['createdTime']); echo $normaldate; } ?>
(The basic code structure is okay i.e. using different columns in Select,
the code will produce results. The above is just an excerpt from the script.)
Is that the complete code you have entered? If it is so, I don't see your loging into mysql. I don't need to see that, however, first login into mysql, then perform the query.
it should be like this:
@$connect=mysql_connect('host', 'user', 'pass');
if (!$connect){echo 'Login failed'.mysql_error();}
@$select = 'SELECT createdTime FROM artman_article';
@$result = mysql_query($select, $connect); /*$select is the query statement, and $connect is the connection identifier, so the mysql_query will use the correct connection.*/
if (!$result) {
die('<p>Error performing query: '. mysql_error().'</p>');
}
// Display each rec
$unixdate= mysql_fetch_array($result);
$normaldate = unixtojd($unixdate['createdTime']); /* or try $normaldate = unixtojd($unixdate[0]); in case the mysql_fetch_array has returned a number indexed array. */
echo $normaldate;I think it should be like this
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
I miss my mind the most...."
Mark Twain
•
•
Join Date: Oct 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Nope. Tried $normaldate = unixtojd($unixdate[0]); also.
Returning a blank screen.
This is what I have. The Select and Display portions should
be the same as your example.
Again, this script does work with different columns. Thanks again for the assist.
Returning a blank screen.
This is what I have. The Select and Display portions should
be the same as your example.
•
•
•
•
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Featured Article Candidates</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<font
<?php
// Connect to the db server
$dbcnx = @mysql_connect('localhost', 'user', 'password');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the database
if (!@mysql_select_db('grow')) {
exit('<p>Unable to locate the ' .
'database at this time.</p>');
}
?>
<p>Featured Article Candidates</p>
<blockquote>
<?php
$result = @mysql_query('SELECT createdTime FROM artman_article');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display text
$unixdate= mysql_fetch_array($result);
$normaldate = unixtojd($unixdate[0]); /* or try $normaldate = unixtojd($unixdate[0]); in case the mysql_fetch_array has returned a number indexed array. */
echo $normaldate;
}
?>
</blockquote>
</font>
</body>
</html>
Again, this script does work with different columns. Thanks again for the assist.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- MySQL SELECT rows In a Date Range (MySQL)
- Inserting date in format DD-MM-YYYY in MySQL (MySQL)
- Date Formatting Calculations!!! (ASP.NET)
- reformatting MySQL date (yyyy-mm-dd) (PHP)
- Date formatting? (Pascal and Delphi)
- mysql date ALWAYS = 0000-00-00 00:00:00 (PHP)
Other Threads in the PHP Forum
- Previous Thread: pase xml with php
- Next Thread: php mysql drop down list


Linear Mode