sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Brad Weiland's Avatar

Between Dates


Question posted by: Brad Weiland (Newbie) on August 29th, 2008 04:32 AM
Hi,

I'm new to SQL and I have the following quesiton.

I have table of data as follows:

Date
31-01-2007
12-31-2007
31-01-2008
31-12-2008

If a want to create an if statement that says if date falls between 31-01-2007 and 12-31-2007 put Year 1, if date falls between 31-01-2008 and 31-12-2008 put Year 2, etc.

Do I use the following formula:

CASE When Date >=31-01-2007 AND <=12-31-2007 THEN "Year 1,
2 Answers Posted
Atli's Avatar
Atli August 30th, 2008 08:35 PM
Moderator - 2,760 Posts
#2: Re: Between Dates

Hi.

You could use the BETWEEN ... AND syntax. Like:
Expand|Select|Wrap|Line Numbers
  1. SELECT 2 BETWEEN 1 AND 3;

Replacing the numbers with dates.
Brad Weiland's Avatar
Brad Weiland September 4th, 2008 04:25 AM
Newbie - 2 Posts
#3: Re: Between Dates

I figured it out the answer to my question
Expand|Select|Wrap|Line Numbers
  1. CASE WHEN Invoice Date BETWEEN '01-APR-2005' AND '31-MAR-2006' THEN '05-06' ELSE CASE WHEN Invoice Date BETWEEN '01-APR-2006' AND '31-MAR-2007' THEN '06-07' ELSE '0' END END
Last edited by Atli : September 4th, 2008 at 11:34 PM. Reason: Added [code] tags.
Reply
Not the answer you were looking for? Post your question . . .
197,016 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,016 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top MySQL Contributors