1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] How to I query using date only from a timestamp column in Spring?

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 10, 2024.

  1. Stack

    Stack Membro Participativo

    I have a Date object myCurrentDate which is in this format '2024-09-10 00:00:00.0'.

    Date myCurrentDate = calendarRepository.getMyCurrentDate();


    I have a product_table with create_date column which is of type timestamp. Each day, many products may be added to the product_table which will have different timestamps. For example:

    product_name​
    create_date​
    Sugar​
    2024-09-10 11:37:25​
    Chips​
    2024-09-08 12:20:52​
    Coffee​
    2024-09-10 15:12:33​
    Oranges​
    2024-09-10 20:52:15​

    I need to use the Date object myCurrentDate to find all the rows that were created that day. So in my example, it should return Sugar, Coffee and Oranges but not Chips.

    List<Products> productsReults= productRepository.findByCrtDt(myCurrentDate);


    Jpa repository looks like this

    List<Products> findByCrtDt(Date myCurrentDate)


    Currently, it is not returning anything because myCurrentDate does not match anything due to the timestamp differences 2024-09-10 00:00:00.0 is not equal to 2024-09-10 11:37:25 and hence does not find Sugar, for example. What would I need to do so that I can return all the desired results. Is there any way I can ignore the hours, minutes, seconds portion? I cannot change the database column type to Date from Timestamp.

    Continue reading...

Compartilhe esta Página