How to convert a date that is in string format in the database when doing a query?

Asked

Viewed 579 times

1

I have a date that is in string format in the database "dd/MM/yyyy" and I needed to return in my query the dates from today. How can I do this conversion in the query to compare with today? Thank you in advance!

update: I’m using the command minha_data > date('now') I have 3 dates in my bank 2/7/2015, 3/12/2015 and 3/3/2016, but is returning only the last date, should return the last 2.

  • Are you sure date('now') is in format dd/mm/yyyy? He may be in mm/dd/yyyy.

  • yes, I recorded in this format, and when return is like this too.

2 answers

1

It is very likely that the result of date('now') does not come in format dd/mm/yyyy (the standard is yyyy/mm/dd).

You can apply a formatting with strftime() so that the return of date() be in the format your dates are saved.

minha_data > strftime('%d/%m/%Y', date('now'));

0

In php use:

echo date('d/m/Y')

Another question, why are you using it in the local format? Is this configured in the bank? Usually date fields in database use the DATE field type, this will provide you with the possibility of comparing date ranges, whether your field is like VARCHAR is probably wrong or its use is specific for this.

  • What the question has to do with PHP?

  • Really, I didn’t notice the language, apologies.

  • Able, it happens =)

Browser other questions tagged

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