If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > trunc to_date to_char

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #16 (permalink)  
Old 07-07-09, 10:55
sunsail sunsail is offline
Registered User
 
Join Date: Dec 2008
Posts: 99
Quote:
Originally Posted by beilstwh
trunc('01-02-2009') ONLY works because your NLS_DATE format is mm-dd-yyyy. At my site it is dd-mon-rr. Do not get into the habit of relying on the NLS settings, if it changes or the software is at another site it will always fail. Use

to_date('01-02-2009','mm-dd-yyyy')

Because the trunc is expecting a date, it implicitly converts the string to a date and then truncs it. A very bad habit to get into.

Thanks for the hint.So it must be like this

to_date('01-02-2009','mm-dd-yyyy')=to_date('send_date','mm-dd-yyyy')

Best Regards
Reply With Quote
  #17 (permalink)  
Old 07-07-09, 11:48
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
for Oracle characters between single quote marks are STRINGS
'send_date' -- is a string & not a valid date regardless of transformation.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #18 (permalink)  
Old 07-07-09, 12:19
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
Quote:
Originally Posted by sunsail
Hi Flyboy

trunc(send_date)=trunc('01-022009') this is what I posted,I mistyped it.I m sorry I was trying to write quickly.But it is suprising you tried it as I wrote it.

Try this
trunc(send_date)=trunc('01-02-2009').It works in oracle11G.

You could have assumed it easily mistyping.
In fact, firstly I thought it means first two months (January and February) in the year 2009.
Even after correcting, it is only a string. Only you know whether it is January, 2nd or February, 1st (luckily year has 4 digits; there could be other possible dates in play with 2 digit year).

I wonder, whether you
Quote:
Originally Posted by flyboy
read description of these functions (TO_TIMESTAMP, TO_DATE, TO_CHAR, TRUNC) before using them.
and read my first post, as everything is there.

If SEND_DATE has DATE data type, it is a mistake to pass it to TO_DATE function, as it accepts parameter with VARCHAR2 data type.
On the other hand, '01-02-2009' has VARCHAR2 data type; TO_DATE with appropriate format mask converts it to DATE datatype (similarly TO_TIMESTAMP converts it to TIMESTAMP data type). This is your aim, you shall
Quote:
Originally Posted by flyboy
compare two values with the same type
Please, sit down for a while, read the documentation, have a look at some examples (yes, even the documentation contains some) and then start creating some conditions with the rules I posted.
Reply With Quote
  #19 (permalink)  
Old 07-08-09, 07:04
sunsail sunsail is offline
Registered User
 
Join Date: Dec 2008
Posts: 99
Here what I got from this thread ?

@ send_date has date type in the table

send_date=to_date('01-01-2010','DD-MM-YYYY')

or

trunc(send_date)=to_date('01-01-2010','DD-MM-YYYY')



@ send_date has date timestamp in the table,this could be variations of timestamp,like timestamp(3),timestamp(6)

send_date=timestamp('01-01-2010','DD-MM-YYYY')



@ send_date has varchar type,or string

to_date(send_date,'mm-dd-yyyy')=to_date('01-02-2009','mm-dd-yyyy')

to_timestamp(send_date,'mm-dd-yyyy')=to_timestamp('01-02-2009','mm-dd-yyyy')
Reply With Quote
  #20 (permalink)  
Old 07-08-09, 09:01
beilstwh beilstwh is offline
Lead Application Develope
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 2,222
that looks correct
__________________
Bill
You do not need a parachute to skydive. You only need a parachute to skydive twice.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On