0

i want to do search depend on date , when i use this statement it gives me empty result

Select * from apps.xx_fa_track where TO_CHAR(trx_date, 'mm/dd/yyyy') = '5/25/2014'

Select  to_char(sysdate, 'MM/DD/YYYY') FROM apps.xx_fa_track 

Can someone please help?

2
  • I suppose mm gives you two digits of month (e.g. 05), and you compare to one-digit month (5). When in doubt, select ... from dual is your friend, it allows you to evaluate arbitrary expressions and see if they make sense. Commented May 25, 2014 at 9:27
  • yes thats work , but the problem is in my code i send date in jquery mobile formated like 5/25/2014 !! and i can't change it :( Commented May 25, 2014 at 9:34

2 Answers 2

3

You can use the FM format modifier to stop the string versrion of the date having leading zeros:

where TO_CHAR(trx_date, 'FMmm/dd/yyyy') = '5/25/2014'

SQL Fiddle of the difference.

But it's generally better to convert your fixed value to the column's data type:

where trx_date = TO_DATE('5/25/2014', 'mm/dd/yyyy')

If your trx_date includes a time portion you can use a range to cover the whole day, but not sure that's needed here.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for pointing out that it is better to convert the constant. However, you might need trunc(trx_date) = TO_DATE('5/25/2014', 'mm/dd/yyyy') for the same logic.
0

I guess you should format month in your date with two digits "05/25/2014". Like here:

Select * from apps.xx_fa_track where TO_CHAR(trx_date, 'mm/dd/yyyy') = '05/25/2014'

1 Comment

yes thats work , but the problem is in my code i send date in jquery mobile formated like 5/25/2014 !! and i can't change it :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.