{"id":22,"date":"2011-06-12T13:54:59","date_gmt":"2011-06-12T10:54:59","guid":{"rendered":"http:\/\/fatihacar.com\/blog\/?p=22"},"modified":"2011-06-15T02:43:11","modified_gmt":"2011-06-14T23:43:11","slug":"date-functions-in-oracle","status":"publish","type":"post","link":"http:\/\/www.fatihacar.com\/blog\/date-functions-in-oracle\/","title":{"rendered":"Date Functions in Oracle"},"content":{"rendered":"<p>Oracle default date format DD-MON-RR (14-MAY-11) for English Language Database. DD\/MM\/YYYY(14\/05\/2011) for Turkish. You can only subtraction between two dates. The result is day count. <\/p>\n<p><strong>ROUND and TRUNC for Date<\/strong><\/p>\n<p>ROUND with &#8216;MONTH&#8217; => If the day is 16 or more than 16, the date rolls next month and the day makes 1.<br \/>\nROUND with &#8216;YEAR&#8217; => If the month is 7 or more than 7, the date rolls next year and the date makes 01-JAN.<br \/>\nTRUNC with &#8216;MONTH&#8217; => The day makes 01 and the month does not change.<br \/>\nTRUNC with &#8216;YEAR&#8217; => The day and the month make 01-JAN and the year does not change. <\/p>\n<blockquote><p>sysdate : 20-JUL-03<\/p>\n<p>ROUND(sysdate,&#8217;MONTH&#8217;) = 01-AUG-03<br \/>\nROUND(sysdate,&#8217;YEAR&#8217;) = 01-JAN-04<br \/>\nTRUNC(sysdate,&#8217;MONTH&#8217;) = 01-JUL-03<br \/>\nTRUNC(sysdate,&#8217;YEAR&#8217;) = 01-JAN-03<\/p><\/blockquote>\n<p><strong>ADD_MONTHS<\/strong><\/p>\n<p>You can increase or decrease month with add_months function.<\/p>\n<blockquote><p>sysdate : 10-APR-08<\/p>\n<p>select add_months(sysdate,1) from dual;<\/p>\n<p>Result : 10-MAY-08<br \/>\nor<br \/>\nselect add_months(&#8217;15-MAY-11&#8242;,-1) from dual;<\/p>\n<p>Result : 15-APR-11<\/p><\/blockquote>\n<p><strong>TO_DATE<\/strong><\/p>\n<p>If you do not know date format, you can use to_date to convert to the format you want. For example; default date format &#8216;DD-MON-YYYY&#8217; for hire_date column. But you can to_date for &#8216;dd-mm-yyyy&#8217; date format.<\/p>\n<blockquote><p>select * from employees where hire_date = to_date(&#8217;01-04-2011&#8242; , &#8216;dd-mm-yyyy&#8217;);<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Oracle default date format DD-MON-RR (14-MAY-11) for English Language Database. DD\/MM\/YYYY(14\/05\/2011) for Turkish. You can only subtraction between two dates. The result is day count. ROUND and TRUNC for Date ROUND with &#8216;MONTH&#8217; => If the day is 16 or more than 16, the date rolls next month and the day makes 1. ROUND with&#8230;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[90,91],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-oracle-sql","tag-oracle","tag-oracle-sql"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p39NFI-m","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":17,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":57,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions\/57"}],"wp:attachment":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}