2

I created a table in which i used timestamp column which tells the record is updated on that time and date.

create table age_info (age tinyint not null,created_on timestamp not null );

But i want to change display like this.
select date_format(Now() ,'%W, %e %M %Y @ %r');

Tuesday, 31 July 2015 @ 02:32:16 PM

But don't know how to do it. When i insert values

insert into age_info(age) values (19);

in the table it show like this.

age      created_on
 19     2015-07-31 18:55:01

I Don't know how to use this function date_format with timestamp column to show like that format.

Thanos Markou
  • 2,587
  • 3
  • 25
  • 32
Ven Nilson
  • 969
  • 4
  • 16
  • 42
  • Possibly this - http://stackoverflow.com/questions/9251561/convert-timestamp-to-date-in-mysql-query ? – Giles Jul 07 '15 at 09:50

3 Answers3

3

I think this will help you to solve the answer

SELECT DATE_FORMAT(`created_on` , '%W, %e %b %Y @ %r') FROM `age_info`;

To insert,

 INSERT INTO `age_info` (`age`) select DATE_FORMAT(now() , '%W %e, %b %Y @ %r')created_on from age_info

Note that, You need to change the table field to varchar.

Ven Nilson
  • 969
  • 4
  • 16
  • 42
Kiran LM
  • 1,359
  • 1
  • 16
  • 29
0

You can keep the format you want by changing your column definition to a text column. Is that what you really want? You'll lose all the benefits a timestamp column offers (easy date and time calculations, etc).

MeanGreen
  • 3,098
  • 5
  • 37
  • 63
0

You can't change the datetime column type to store the data as you want, it changes the meaning of the datetime and no advantage of it, although you can use it to select the format whatever you want using date_format() function.

Aman Aggarwal
  • 17,619
  • 9
  • 53
  • 81