Mysql order by field date original value

Asked

Viewed 76 times

1

I’m doing a query and I’m transforming the data no formato and then I want to use the data_vencimento original in order by but it doesn’t 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 doesn’t work, I’m doing a variable data_vencimento with the same field name but I need to do this to avoid complications in jquery.

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

1 answer

2


I believe that qualifying the field works, I have no 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
  • Yeah buddy that’s right worked out, Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.