Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
| Search | Today's Posts | Mark Forums Read
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 13th, 2009, 01:03 AM
Authorized User
Points: 306, Level: 6
Points: 306, Level: 6 Points: 306, Level: 6 Points: 306, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , .
Posts: 54
Thanks: 2
Thanked 0 Times in 0 Posts
Default How to Determine the first day of the current Fiscal Year

I am a SQL Server developer who is trying to to learn Oracle SQL. I am trying to write a query that will 1) determine the month number and if the number is 10, 11, or 12, will return '01-Oct-' of the current Calendar year. If the month number is between 1 and 9, it returns '01- Oct-' of the last Calendar year (YYYY = current Calendar year minus 1 year).

I was playing with the EXTRACT function to get the year and month, but was unable to formulate the '1-Oct-YYYY' where YYYY is the current or previous calendar year.

Could anyone point me to an example of how to do this in Oracle?
__________________
--- Tom
  #2 (permalink)  
Old February 13th, 2009, 01:46 AM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default Google is your friend

http://www.google.com/search?hl=en&c...ns&btnG=Search

which leads to

http://www.psoug.org/reference/date_func.html

So...something like...
Code:
SELECT TO_DATE( CASE WHEN TO_NUMBER( TO_CHAR( SYSDATE,'MM') ) IN ( 10, 11, 12 )
                THEN '1-Oct-' + TO_CHAR(SYSDATE,'YYYY') 
                ELSE '1-Oct-' + TO_CHAR( TO_NUMBER( TO_CHAR(SYSDATE,'YYYY') ) - 1 )
                END ) As FiscalYearStart
And here I thought SQL Server was braindead when it comes to datetime functions! (And it is, and so is Oracle a lot, when compared to Access or MySQL!!!)
The Following User Says Thank You to Old Pedant For This Useful Post:
tcarnahan (February 15th, 2009)
  #3 (permalink)  
Old February 16th, 2009, 12:39 PM
Authorized User
Points: 306, Level: 6
Points: 306, Level: 6 Points: 306, Level: 6 Points: 306, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , .
Posts: 54
Thanks: 2
Thanked 0 Times in 0 Posts
Thumbs up Small correction to solution

This is a good solution except for one small syntactical error ... very easy to make. The code should read:

Code:
SELECT TO_DATE( CASE WHEN TO_NUMBER( TO_CHAR( SYSDATE,'MM') ) IN ( 10, 11, 12 )
                THEN '1-Oct-' || TO_CHAR(SYSDATE,'YYYY') 
                ELSE '1-Oct-' || TO_CHAR( TO_NUMBER( TO_CHAR(SYSDATE,'YYYY') ) - 1 )
                END ) As FiscalYearStart
Because I work so much in SS, I did not catch the concatenation part at first. Oracle uses double pipe symbols vs. "+" for concatenation.

Just the same, I really appreciate your help!
__________________
--- Tom
  #4 (permalink)  
Old February 16th, 2009, 09:52 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

DOH! I KNEW THAT!

I worked with Oracle for a grand total of about 2 months in 2001, but I do remember that! Shame on me! Thanks for the fix!


Similar Threads
Thread Thread Starter Forum Replies Last Post
subtracting 1 day from the current date Jeff C# 2 March 12th, 2009 01:16 AM
To get current year darshil XSLT 3 May 21st, 2007 06:46 AM
Date= starting of the current fiscal year rmanu7382 Reporting Services 0 April 3rd, 2006 12:42 AM
Fiscal Year jemacc SQL Server 2000 4 October 7th, 2004 03:05 AM
get year,month,day,hour... kobystud C# 1 July 16th, 2004 04:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.