1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to format date in Hibernate HQL?

Discussion in 'Programming' started by inegoita, Nov 5, 2019.

  1. #1
    hi,

    I am using Hibernate in my Spring Java app and I have an object Event with a field eventDate of type Date.

    What are my options for formatting a date to a string using the YYYY-MM-DD format? I guess I could retrieve the field as a date, and then format the date in Java, but that's probably not too efficient.

    My app is currently setup to work with a MySQL database, but I would also like it to work on Postgresql.

    thanks in advance!
     
    inegoita, Nov 5, 2019 IP
  2. LewisH95

    LewisH95 Greenhorn

    Messages:
    118
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    23
    #2
    You can use the following that converts a date to a string with the specified format:

    to_char(mydate,'yyyy-mm-dd')
     
    LewisH95, May 7, 2020 IP