0

I'm a total beginner in mysql. I have a table with 5 columns. One of the columns is of type DATE. What I want is, read all the columns of one row and from the DATE column read only the date without timezone. How can I achieve this?
I know that selecting all the fields in one row requires query like this:

SELECT * FROM table_name;

And to display only the date from DATE type (the answer I found in another question) is:

select DATE_FORMAT(date,'%d') from tablename

Is there a way to merge these queries into one that would do what I want it to do?

EDIT: This mysql database is integrated into a Node.js server. I wanted to make one query to get all the information from one row with an ID that I have and read the results in Node.js.

This is how I made the table in the database:

CREATE TABLE requests (id INT NOT NULL AUTO_INCREMENT,patient_name TEXT NOT NULL, patient_email TEXT NOT NULL, requested_date DATE NOT NULL,requested_time TIME NOT NULL,status ENUM('submitted','accepted','declined') , PRIMARY KEY(id));

When I make this query in Node.js:

SELECT * FROM requests WHERE id = 4;

I get the 4th row, and when I read the 'requested_date' it has the value: e.g. Tue Feb 24 2015 00:00:00 GMT+0100 (CET). What I want is to read only the date without the "00:00:00 GMT+0100 (CET)" part.

Community
  • 1
  • 1
Amer Hukic
  • 1,494
  • 1
  • 19
  • 29
  • Put in an example of your data as it sits in the database, and an example of what you want as a result. That will help. – castis Feb 26 '15 at 21:04

1 Answers1

1

If you want to select all the columns and format the date, you can explicitly list all the columns in your SELECT statement:

SELECT id , ... , DATE_FORMAT(`requested_date`,'%d') as requested_date_format, ... 
FROM table_name WHERE id=4;

Some people prefer this method because it easy to see what columns will be in the result.

OR

You can still use the * method and just add the date at the end.

SELECT *, DATE_FORMAT(`requested_date`,'%d') as requested_date_format
FROM table_name WHERE id=4;

Then you will get all the columns plus the formatted date. Note that the requested_date column will appear twice (kind of), but the formatted date will be in the column: requested_date_format.

Dan
  • 10,614
  • 5
  • 24
  • 35