joining between 2 different dates ? [message #621249] |
Tue, 12 August 2014 03:22 |
tondapi
Messages: 99 Registered: August 2007 Location: usa
|
Member |
|
|
Hi,
I my table I have a column called day_id(mm/dd/yyyy hh:mm:ss) and I need to join with date column(mm/dd/yyyy).
How to join this 2 columns ?
Thanks,
|
|
|
|
|
|
|
|
Re: joining between 2 different dates ? [message #621258 is a reply to message #621257] |
Tue, 12 August 2014 03:39 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
tondapi wrote on Tue, 12 August 2014 14:06lalit it is typo error
If you do that typo in your code, it will take month instead of minutes. In your case, anyway, using trunc will get rid of the timestamp part. Follow Littlefoot's suggestion.
|
|
|
|
|
Re: joining between 2 different dates ? [message #621263 is a reply to message #621261] |
Tue, 12 August 2014 04:03 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
You need to get your head around the fact that dates and timestamps do not have formats when stored in the DB. If you state the data is in a particular format then we have to wonder if it's actually a varchar column.
The formats are used when converting the dates to char for display purposes.
|
|
|
|
|
Re: joining between 2 different dates ? [message #621276 is a reply to message #621251] |
Tue, 12 August 2014 06:02 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Littlefoot wrote on Tue, 12 August 2014 13:54Truncate the first (DAY_ID) column, and then join them, such as
where trunc(day_id) = the_second_date_column
SQL> select * from dual where trunc(systimestamp)=sysdate;
no rows selected
OP needs to apply trunc on both, timestamp and date.
SQL> select * from dual where trunc(systimestamp)=trunc(sysdate);
D
-
X
P.S. : Perhaps this is what Michel was pointing to.
[Updated on: Tue, 12 August 2014 06:04] Report message to a moderator
|
|
|
Re: joining between 2 different dates ? [message #621282 is a reply to message #621276] |
Tue, 12 August 2014 06:44 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
depends on what's in the date column, doesn't it?
If the date column is populated with sysdate then yes.
If it's populated with trunc(sysdate), or anything else that specifies date and not time, then no.
|
|
|
Re: joining between 2 different dates ? [message #621285 is a reply to message #621282] |
Tue, 12 August 2014 06:57 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
cookiemonster wrote on Tue, 12 August 2014 17:14depends on what's in the date column, doesn't it?
Yes, agreed. As OP said LF's query worked, it can be assumed the date column is populated with trunc(sysdate).
|
|
|
Re: joining between 2 different dates ? [message #621287 is a reply to message #621276] |
Tue, 12 August 2014 07:17 |
|
Michel Cadot
Messages: 68647 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Lalit Kumar BP.S. : Perhaps this is what Michel was pointing to.
I just wanted to make it think about his "is working".
cookiemonsterdepends on what's in the date column, doesn't it?
Yes, and so my question (still answered):
Quote:A DATE column also contains a time part (so is not "mm/dd/yyyy").
What kind of join do you actually want: up to second part or on day part?
The "solution" depends on this.
|
|
|