How to perform date operations in hibernate

前端 未结 8 1085
既然无缘
既然无缘 2020-12-10 03:00

I want to perform data time operations using hibernate HQL.

I want to add and subtract two dates as well as I want to subtract 1 year or 1 month from a particular da

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 03:40

    In Hibernate/MySQL (at least) You can convert to and from a Unix Timestamp. Since the unix timestamp is an integer you can add an integer number of seconds to it.

    FROM_UNIXTIME(UNIX_TIMESTAMP(date)+ (allowedTimeWindow*86400)) as deadline
    

    It has limitations but it's a lot easier than the approaches above.

提交回复
热议问题