Avatar of dloj
dloj
Flag 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.
MySQL ServerPHP

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
Ray Paseur

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
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.
arnold

You need to use from_unixtime(last_updated) as the input to your format string
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
arnold

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.
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 |
Ray Paseur

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
dloj

ASKER
Thanks Ray,

I had the column name and the date format %m %d %y as you have shown reversed.
Ray Paseur

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
Ray Paseur

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
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.
Ray Paseur

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?