1

My application supports both databases oracle and MySQL, now I need to calculate difference between two dates .

My code is working with Oracle as it supports " - " operator, but it will not work with MySQL. MySQL has a DATEDIFF function to calculate difference.

  Query query1 = entityManager.createQuery("select ast.id,ast.name from ActSubT ast where ast.unSubDt - ast.subDt <= 1 ");
 List<Object> result=query1.getResultList();

Do we have any option by which I can calculate difference with same query and should work with both MySQL and Oracle? I don't want to write two different queries

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rajesh Khore
  • 325
  • 1
  • 3
  • 7
  • Minus operator works in all the database that is mentioned in the question. It works in MySql too: https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=111c51faf9141479035b8ed230b29a36 – Popeye Sep 06 '19 at 08:47
  • only problem the minus is very limited.. @Tejash .. topicstarter has no other choice then write two queries to support two differenct SQL dialects or needs to program a SQL [transpiler](https://en.wikipedia.org/wiki/Source-to-source_compiler) with sits in between the application and RDMSes like a proxy and can accept one SQL writing style to work on both RDMSes .. – Raymond Nijland Sep 06 '19 at 08:53
  • @RaymondNijland I just cheked - is working with mysql, what does it mean by "only problem the minus is very limited" – Rajesh Khore Sep 06 '19 at 09:21

0 Answers0