I am passing a date (DateTime.Now) from C# code to Oracle procedure. I wanted to retrieve all the values from table between
DateTime.Now – 1 11:10:00 AM to DateTime.Now 11:09:59 AM
How do I write a oracle condition for this?
Note: Column ‘CreateDate ‘ is a Date
I have this right now..
CreateDate >= TO_DATE(to_char(in_CreateDate), 'DD-MON-YY') - 1
and CreateDate < TO_DATE(to_char(in_CreateDate), 'DD-MON-YY') + 1
You can do math on the date as you suggest. Here’s a quick example (you can substitute your DateTime.Now and proper format string instead of my hardcoded example):
Notice how I’m taking the input date, truncating it (to get the date without the time) and then adding the hours and minutes to that base date.
You can expand on this to use the
BETWEENkeyword and get this:Or, if you’re always passing
DateTime.Nowyou can just use the date from the database: