Mysql order by field date original value

1

I'm doing a query and I'm transforming the data no formato brazilian and then I want to use the data_vencimento original in order by but it does not work

code:

SELECT *,DATE_FORMAT(data_vencimento,'%d/%m/%Y') as data_vencimento, DATE_FORMAT(data_pagamento,'%d/%m/%Y') as data_pagamento FROM cta_pagar WHERE id_nota='$nota' AND id_fornecedor='$fornecedor' ORDER BY data_vencimento ASC

I know why it does not work, I'm making a data_vencimento variable with the same field name but I need to do this to avoid complications in jquery.

What I ask you to help me is how to do when I give ORDER BY data_vencimento ASC it uses the original value of the field instead of the formatted date (string).

    
asked by anonymous 26.05.2014 / 17:40

1 answer

2

I believe that qualifying the field works, I do not have Mysql and I have no way to test

SELECT *,DATE_FORMAT(DATA_VENCIMENTO,'%d/%m/%Y') AS DATA_VENCIMENTO,     DATE_FORMAT(DATA_PAGAMENTO,'%d/%m/%Y') AS DATA_PAGAMENTO 
FROM CTA_PAGAR 
WHERE ID_NOTA='$nota' 
AND ID_FORNECEDOR='$fornecedor' 
ORDER BY CTA_PAGAR.DATA_VENCIMENTO ASC
    
26.05.2014 / 17:51