Home » RDBMS Server » Server Administration » date format in SQL query
date format in SQL query [message #373023] Fri, 23 March 2001 09:00 Go to next message
Prapoorna
Messages: 6
Registered: October 2000
Junior Member
Can u please let me know the difference in using to_date function and the trunc function for date columns in a SQL query

I have given two similar queries once using to_date and another time using trunc and the ouptput it gives is different.

Query:
select count(*), to_date(timein, 'DD-MON-YY') from usersessions where to_date(timein, 'DD-MON-YY') >= '15-OCT-98' group by to_date(timein, 'DD-MON_YY')

This gives me the correct output but when i give the same query using trunc (saying trunc(timein) ) instead of to_date it gives 'no rows selected'....

I would appeciate any help regarding this..
Thank You......
Re: date format in SQL query [message #373055 is a reply to message #373023] Sat, 24 March 2001 04:36 Go to previous messageGo to next message
Arjun V
Messages: 14
Registered: March 2001
Junior Member
Trunc(timeindate) is different from to_date.
to_date is conversion function while trunc is to truncate the date to lower date..
Re: date format in SQL query [message #373061 is a reply to message #373023] Sun, 25 March 2001 04:55 Go to previous message
Narendra
Messages: 10
Registered: March 2001
Junior Member
to_date function is used to convert a string in
date format TO date data type.
eg. where lastin >= to_date('01-JAN-2001','DD-MON-YYYY')

here lastin is a date field in table.
trunc function is used to eliminate time part of date.
Previous Topic: Re: Setting the SQL Prompt to show up the host name
Next Topic: How to store image file into long raw column and...
Goto Forum:
  


Current Time: Wed Jun 26 06:45:18 CDT 2024