This is my select statement: -
SELECT
-
a2.conditionindex, a1.timestamp,
-
a3.alarmdefinitionname, a3.alarmdefinitionseverity,
-
a2.tripsubjectname,a2.tripcontextname, a2.tripvalue,
-
a5.conditionname, a5.conditiontype
-
FROM alarmnotification AS a1,
-
alarmnotificationdetail AS a2,
-
alarmdefinition AS a3,
-
alarmcondition AS a5
-
WHERE a1.notificationid=a2.notificationid
-
AND a1.definitionid=a3.databaseidentifier
-
AND a2.conditionid=a5.databaseidentifier
-
ORDER BY a1.timestamp, a3.alarmdefinitionseverity";
right now, time stamps is displayed: month/day/year hour/min/sec am/pm
MY QUESTIONS IS:
I want my timestamp to only display hour/min/sec
how do I change my select statement.
thank you
12 2276 Atli 5,058
Expert 4TB
Hi.
Try the DATE_FORMAT function.
Should allow you to convert any date/time type field into whatever format you want.
should I use the date_format in the create table for example,
CREATE TEXT TABLE ALARMNOTIFICATION(
TIMESTAMP DATE_FORMAT('HH:MM:SS'),
No, it will be used at the time of SELECTing data. Did you look at the link provided by Atli?
I used it in the select statement like this:
"SELECT a2.conditionindex, DATE_FORMAT(a1.timestamp, '%r'),...
but it only changed the header of the table and not the contents inside the table.
thanks
Atli 5,058
Expert 4TB
This wouldn't change the actual data stored in your table.
It would change the way the data is returned by the SELECT statement.
That is, if these were the actual values inside your table: -
mysql> SELECT Timestamp FROM myTable;
-
+---------------------+
-
| Timestamp |
-
+---------------------+
-
| 2009-01-28 08:45:00 |
-
| 2009-01-28 13:45:00 |
-
| 2009-01-28 03:45:00 |
-
| 2009-01-28 20:45:00 |
-
+---------------------+
And you execute this query: -
SELECT DATE_FORMAT(timestamp, '%r') AS 'Time'
-
FROM myTable
-
You would get: -
mysql> SELECT DATE_FORMAT(timestamp, '%r') AS 'Time'
-
> FROM myTable;
-
+-------------+
-
| Time |
-
+-------------+
-
| 08:45:00 AM |
-
| 01:45:00 PM |
-
| 03:45:00 AM |
-
| 08:45:00 PM |
-
+-------------+
another questions:
if in my create table, I want to do it so that there is only hh:mm:ss for a field..do i do it something like this:
CREATE TEXT TABLE ALARMNOTIFICATION(
TIMESTAMP DATETIME(hh:mm:ss),
Atli 5,058
Expert 4TB
No, you would use the TIME data type.
The Reference Manual contains a list of all available data types, as well as everything else you may want to know about the correct usage of MySQL syntax.
What i ment when i said that the data is changed is that when I run:
"SELECT a2.conditionindex, DATE_FORMAT(a1.timestamp, '%r'),...
the file that I am using to print this select statement comes back empty with only the header line being there with the titles of the fields. All of the data is not showing up
Atli 5,058
Expert 4TB
Ok. Then there is either no data fitting your query, or your code is not displaying it properly.
Either way, we would need to see the code to be able to help.
It's damn hard to debug code you can't see :)
There is definitely Data that fits the query, because if comment out if statements that deal with the timestamp, the rest of the fields are populated. This code that i am sending you is the original that displays the output in an excel file but with the timestamp, displays the date, and hour and min. Everything is pretty much correct but I want the timestamp to only display the hr, min and seconds. No date.
Here is parts of the code:
The select statement: -
SELECT
-
a2.conditionindex,
-
a1.timestamp,
-
a3.alarmdefinitionname,
-
a3.alarmdefinitionseverity,
-
a2.tripsubjectname,
-
a2.tripcontextname,
-
a2.tripvalue,
-
a5.conditionname,
-
a5.conditiontype
-
FROM alarmnotification AS a1,
-
alarmnotificationdetail AS a2,
-
alarmdefinition AS a3,
-
alarmcondition AS a5
-
WHERE a1.notificationid=a2.notificationid
-
AND a1.definitionid=a3.databaseidentifier
-
AND a2.conditionid=a5.databaseidentifier
-
ORDER BY a1.timestamp, a3.alarmdefinitionseverity
the Create table code: -
CREATE TEXT TABLE ALARMNOTIFICATION(
-
LOGGINGVERSION DECIMAL(4,2),
-
LOGGINGSTYLE CHAR(1),
-
NOTIFICATIONID INTEGER,
-
MILLISECONDS BIGINT,
-
TIMESTAMP TIMESTAMP,
-
ACTIVATIONID INTEGER,
-
DEFINITIONID INTEGER,
-
DEFINITIONSEVERITY INTEGER,
-
CONSTRAINT PK_ALARMNOTIFICATION PRIMARY KEY(NOTIFICATIONID)
-
);
the php code to desplay the tables: -
while($row=mysql_fetch_array($result)){
-
-
fwrite($debug_handle, $row['conditionindex'] . ",");
-
fwrite($debug_handle, $row['timestamp'] . ",");
-
fwrite($debug_handle, $row['alarmdefinitionname'] . ",");
-
fwrite($debug_handle, $row['alarmdefinitionseverity'] . ",");
-
fwrite($debug_handle, $row['tripsubjectname'] . ",");
-
fwrite($debug_handle, $row['tripcontextname'] . ",");
-
fwrite($debug_handle, $row['tripvalue'] . ",");
-
fwrite($debug_handle, $row['conditionname'] . ",");
-
fwrite($debug_handle, $row['conditiontype'] . ",");
-
fwrite($debug_handle, "\r\n");
-
-
if ((substr($row['timestamp'],11,12)>=$timeFrame_min) && (substr($row['timestamp'],11,12)<$timeFrame_max)) {
-
fwrite($handle, "<tr>");
-
fwrite($handle, "<td>" . $row['timestamp'] . "</td>");
-
fwrite($handle, "<td>" . $row['alarmdefinitionname'] . "</td>");
-
if ($row['alarmdefinitionseverity'] == 1)
-
fwrite($handle, "<td> High </td>");
-
elseif ($row['alarmdefinitionseverity'] == 2)
-
fwrite($handle, "<td> Medium </td>");
-
elseif ($row['alarmdefinitionseverity'] == 3)
-
fwrite($handle, "<td> Low </td>");
-
fwrite($handle, "<td>" . $row['tripsubjectname'] . "</td>");
-
fwrite($handle, "<td>" . $row['tripcontextname'] . "</td>");
-
if ($row['tripvalue'] == 1)
-
fwrite($handle, "<td> DOWN </td>");
-
else
-
fwrite($handle, "<td>" . $row['tripvalue'] . "</td>");
-
fwrite($handle, "<td>" . $row['conditionname'] . "</td>");
-
if ($row['conditiontype'] == 1)
-
fwrite($handle, "<td> Instrumentor </td>");
-
elseif ($row['conditiontype'] == 2)
-
fwrite($handle, "<td> Process Watcher </td>");
-
else
-
fwrite($handle, "<td> ERROR#NOTENOUGHINFO# </td>");
-
fwrite($handle, "</tr>");
-
}
-
}
the Java code that gets the time: -
pw.print(c.get(c.YEAR) + "-" + (c.get(c.MONTH)+1) + "-" + c.get(c.DAY_OF_MONTH) + " " + c.get(c.HOUR_OF_DAY) + ":" + c.get(c.MINUTE) + ":" + c.get(c.SECOND) + ",");
hope that helps a bit.
thanks
Atli 5,058
Expert 4TB
Ok, so I'm assuming the output you need to change is in line #16 of your PHP code?
If so, there are two ways I see.
First, apply the DATE_FORMAT function to your SELECT query, like we have been discussing.
You would have to reflect this change in your if statement on line #14 to. It is expecting the the standard datetime format, so it probably won't work after the format.
Or, you could use the PHP date function in line #16 to alter the timestamp before you print it. This would not require you to actually alter the query, so your timestamp would remain intact if it has to be used elsewhere. Note that you will have to run the timestamp through strtotime to get the Unix timestamp before you run it through the date function.
Like: -
echo date("H:i:s", strtotime($row['timestamp']));
P.S.
Where does that Java code fit in?
You know, PHP can do that to: - echo date("Y-m-d H:i:s", time());
Thanks for the help,
That made the correct conversion.
thank you
Sign in to post your reply or Sign up for a free account.
Similar topics
by: androtech |
last post by:
Hello,
I'm looking for a function that returns a date range for a specified week
number of the year.
I'm not able to find functions like this anywhere. Any pointers/help would
be much...
|
by: Khurram |
last post by:
I have a problem while inserting time value in the datetime Field.
I want to Insert only time value in this format (08:15:39) into the SQL
Date time Field.
I tried to many ways, I can extract...
|
by: maflatoun |
last post by:
Hi,
I have the following function to convert UTC time to Local time. It
works perfect for GMT- (Minus) time zones however it provides incorrect
results for GMT+(Plus) time zones?
// Format to...
|
by: Assimalyst |
last post by:
Hi,
I have a working script that converts a dd/mm/yyyy text box date entry
to yyyy/mm/dd and compares it to the current date, giving an error
through an asp.net custom validator, it is as...
|
by: Luvin lunch |
last post by:
Hi,
I'm new to access and am very wary of dates as I have limited
experience in their manipulation and I know if they're not done
properly things can turn ugly quickly.
I would like to use a...
|
by: Jim in Arizona |
last post by:
I have a gridview that's being populated from an access db query. The
problem I'm having is that the date/time fields in access that are
populating the gridview are showing both date and time, when...
|
by: colleen1980 |
last post by:
Hi: Data in my table is in that format. How to i separate date with
time.
11/9/2006 10:10:46 AM
Thank You.
|
by: Geoff Cox |
last post by:
Hello,
at the moment I can add the combined date and time into MySQL using
php
$dt1 = date("Y-m-d H:i:s");
is it possible to add the date and time separately?
I thought it might be
|
by: yasirmturk |
last post by:
Standard Date and Time Functions
The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
|
by: ahmurad |
last post by:
Dear Brothers,
I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As
MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |