Show query by current date

1

I would like to show a query for the current date, because when I save in my table I have the field fecha and it is type date .

The format to show and save the date is this:

void cargar() {

    Calendar cal = new GregorianCalendar();
    int anio=cal.get(Calendar.YEAR);
    int mesi=cal.get(Calendar.MONTH);
    int mest=mesi+1;
    int mes=mest;
    int dia=cal.get(Calendar.DATE);
    String fecha= anio+"-"+mes+"-"+dia;
    this.lab_fecha.setText(fecha);

}

I'm doing the query like this but it still shows me all the dates, and what I want to achieve is to show me only the records that have a date of today.

SQL = "SELECT * FROM adelantos WHERE fecha ORDER BY fecha DESC,hora DESC";
    
asked by yoclens 27.02.2017 в 05:26
source

3 answers

1

You have to compare today's date with the date of the records, but you have to give the latter the correct format.

SELECT *
FROM adelantos 
WHERE DATE_FORMAT(fecha, '%Y-%m-%d') = CURDATE()
    
answered by 27.02.2017 / 10:39
source
2

Where you must include the condition

where fecha ="Alguna fecha"

you must correct it in your query:

"SELECT * FROM adelantos WHERE fecha=now() ORDER BY fecha DESC,hora DESC";
    
answered by 27.02.2017 в 06:40
1

You must include now() that refers to the current date of your server or your machine

SELECT * FROM adelantos WHERE fecha = now() ORDER BY fecha DESC,hora DESC
    
answered by 27.02.2017 в 14:33