seleccionando la marca de tiempo máxima cuando la marca de tiempo es un campo de texto

I am trying select the max timestamp value for a field that contains timestamp values, but is actually a text field. Before you say it, I can't change the field type because the app that populates it is not changeable. It's annoying, I know.

The format of the Timestamp is

Wed Mar 02 13:28:59 CST 2011 -> this is actually a text value in MYSQL

Aquí está mi intento:

SELECT DISTINCT MAX(STR_TO_DATE(`Timestamp`, '%d, %m, %Y')) FROM `table`

'Timestamp' is referring to the column called Timestamp.

This just returns NULL values for the timestamp. Thanks for any help.

preguntado el 28 de agosto de 12 a las 14:08

4 Respuestas

This should work for you, also have a look at http://www.w3schools.com/sql/func_date_format.asp

SELECT DISTINCT MAX(STR_To_DATE(`Timestamp`,'%a %b %d %H:%i:%s CST %Y')) 
FROM `table`;

Test case example:

SET @v = 'Wed Mar 02 13:28:59 CST 201';

SELECT STR_To_DATE(@v, '%a %b %d %H:%i:%s CST %Y');

Respondido 28 ago 12, 14:08

Prueba este formato

STR_TO_DATE(`Timestamp`,'%a %b %d %T CST %Y')

Respondido 28 ago 12, 14:08

Prueba esta consulta:

SELECT
  MAX(STR_TO_DATE(`Timestamp`, '%a %b %d %H:%i:%s CST %Y'))
FROM
  `table`

Respondido 28 ago 12, 14:08

Use

SELECT DISTINCT MAX(STR_TO_DATE(`table.Timestamp`, '%d, %m, %Y')) FROM `table`

Respondido 28 ago 12, 14:08

this didn't work :(. I think the format of the string is throwing it off. - hacha

putting the quotes around it gives an 'Unknown column' error. - hacha

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.