Link to home
Start Free TrialLog in
Avatar of dloj
dlojFlag for United States of America

asked on

Selecting Date from Current_timestamp Field

Hi Everyone,
I am creating a mySQL table where one column is last_updated.  I have that as timestamp Type and default CURRENT_TIMESTAMP.  So as people fill out the form to get on the list it marks when they filled out the form.

Through Dreamweaver I am creating a page where the members of the list and shown with the last_updated column.  My issue is I only want the date and not the time to populate the field.  

I have tried DATE_FORMAT('%m %d %y', last_updated) AS DATE and for my table code I have
<td><?php echo $row_Recordset3['DATE']; ?></td>  

It is not working but I am getting no errors just nothing shows up in the last_updated column on the page showing the members of the list.

I am not sure if I have to first separate the date and time from the CURRENT_TIMESTAMP data.  

Any suggestions would be appreciated, thanks in advance.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Please see this article for more information on using DATETIME values in PHP and MySQL.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

This SELECT should get you the ISO-8601 format date, which is the right format for all internal representations.
SELECT DATE_FORMAT(date, '%Y-%m-%dT%TZ') FROM table_name
Avatar of dloj

ASKER

Thanks Ray but that didn't work.  I am still getting nothing in the last_updated column when I enter this sql in phpmyadmin to test:

SELECT first_name, last_initial, phone, email, country, lyears, lmo, ayears,
prg, sponsor, speaker, speaker_phone, outreach_calls, lib, web_infor,
DATE('m/d/Y', 'last_updated') AS DATE from resource_list WHERE web_infor = 'yes'

I get all the information for the members that want to be on the web but do not get  any CURRENT_TIMESTAMP info at all.

Now when I put:

SELECT * FROM `resource_list` WHERE `web_infor`= 'yes';

I get all the members and also get the CURRENT_TIMESTAMP set by default when they entered their info on the form.   I just want the date though and that is my dilema.  

Thanks again for your response.
Avatar of arnold
You need to use from_unixtime(last_updated) as the input to your format string
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dloj,

Could you output the raw data from last_update column along with the show create table to see what the definition of the last_updated column is.
Avatar of dloj

ASKER

Hi Arnold,

Here is my show create table for my resource_list table;

 resource_list | CREATE TABLE `resource_list` (
  `debtors_id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(50) DEFAULT NULL,
  `last_initial` varchar(4) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `email` varchar(50) DEFAULT NULL,
  `country` varchar(50) DEFAULT NULL,
  `lyears` int(5) DEFAULT NULL,
  `lmo` int(5) DEFAULT NULL,
  `ayears` varchar(20) DEFAULT NULL,
  `prg` varchar(4) DEFAULT NULL,
  `sponsor` varchar(4) DEFAULT NULL,
  `speaker` varchar(4) DEFAULT NULL,
  `speaker_phone` varchar(4) DEFAULT NULL,
  `outreach_calls` varchar(4) DEFAULT NULL,
  `lib` varchar(20) DEFAULT NULL,
  `web_infor` varchar(5) DEFAULT NULL,
  `last_updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`debtors_id`)
) ENGINE=MyISAM AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 |
Given this line in the CREATE TABLE...
`last_updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP,

You can probably map that to the column named `abcd` in the code example here:
https://www.experts-exchange.com/questions/28687058/Selecting-Date-from-Current-timestamp-Field.html?anchorAnswerId=40817203#a40817203
Avatar of dloj

ASKER

Thanks Ray,

I had the column name and the date format %m %d %y as you have shown reversed.
Thanks for the points and thanks for using E-E -- those positional arguments often make it hard to remember the order for functions.  I've got an example of how I try to deal with that (Needle, haystack? Haystack, needle?) in this article:
https://www.experts-exchange.com/articles/18409/Using-Named-Parameters-in-PHP-Function-Calls.html

Best regards, ~Ray
Now please do me a favor... Since I posted a tested and working code example, please read the grading guidelines and explain why you marked the grade down.  What were you expecting that you did not get?  Why didn't you give a grade of "A" here?
http://support.experts-exchange.com/customer/portal/articles/481419
Avatar of dloj

ASKER

Hi Ray, Well the answer was to reverse the items in the parenthesis which you obviously knew but you chose to fill the answer with a long example.   Which actually covered the answer at the time.  I found the answer elsewhere actually but went back and saw that you had given the same answer so I gave you the credit.  The long answer was unnecessary, sometimes simple is best.
you obviously knew but you chose to fill the answer with a long example
Which was necessary for me to test the answer before I posted it.  There is a big difference between thinking you know an answer and getting the correct results.  I even told you the exact line number to look at.

Did you read the Experts-Exchange grading guidelines?  If you give a marked-down grade for a perfect answer, what are we to make of that?