Solved

eturn all results only in the same month

Posted on 2008-06-16
7
182 Views
Last Modified: 2010-03-19
i know i have asked something like this yesterday but  this is a different query

i have a date time stamp in my DB (TIMEDATE)  format is like this 2008-06-01 15:16:00.0
i have a variable passed  called 'datepassed' with a format like this: June 2008

now i need to return all results only in the same month, i have this so far but does not return anything.

       SELECT  TIMEDATE
        FROM orders
        WHERE TIMEDATE  = '#datepassed#'

PS i want to group the returned results by day also
0
Comment
Question by:pigmentarts
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 60

Expert Comment

by:chapmandew
Comment Utility
      SELECT  TIMEDATE
        FROM orders
where timedate >= '6/1/2008' and
timedate < '7/1/2008'
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
You can do something like this:

SELECT  TIMEDATE
        FROM orders
        WHERE year(TIMEDATE)  = YEAR('#datepassed#')
        AND month(TIMEDATE)  = month('#datepassed#')
0
 
LVL 60

Expert Comment

by:chapmandew
Comment Utility
But, it will be slow because of the function performed on the field...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 12

Author Comment

by:pigmentarts
Comment Utility
emoreau that seems to work perfect.
chapmandew its a dynamic date so  emoreau answer work a little better

ok so now i am getting results like the following i need to group by the day

         June, 01 2008 15:16:00
      
       June, 01 2008 15:38:00
      
       June, 01 2008 16:15:00
      
       June, 01 2008 18:51:00
      
       June, 02 2008 10:03:00
      
       June, 02 2008 11:09:00
      
       June, 02 2008 12:50:00
      
       June, 02 2008 14:16:00
      
       June, 02 2008 17:17:00
      
       June, 03 2008 09:45:00
      
       June, 03 2008 09:51:00
      
       June, 03 2008 10:10:00
0
 
LVL 7

Expert Comment

by:Zippit
Comment Utility
 SELECT  TIMEDATE
        FROM orders
        WHERE TIMEDATE  BETWEEN ('2008-01-01 00:00:00' and '2008-01-31 23:59:59')
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
Comment Utility
SELECT  distinct CONVERT(VARCHAR(10), TIMEDATE , 120)
        FROM orders
        WHERE year(TIMEDATE)  = YEAR('#datepassed#')
        AND month(TIMEDATE)  = month('#datepassed#')
0
 
LVL 12

Author Comment

by:pigmentarts
Comment Utility
emoreau
 that works thanks
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now