Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: Stefan Wuebbe
  Where is Stefan Wuebbe?
 Hamburg
 Germany
 Stefan Wuebbe
 To: Phillip Bongers
  Where is Phillip Bongers?
 Sydney
 Australia
 Phillip Bongers
Subject: RE: SQL - Datetime field
Thread ID: 183035 Message ID: 183036 # Views: 2 # Ratings: 0
Version: Visual FoxPro 7 Category: Databases, Tables and SQL Server
Date: Friday, July 11, 2008 11:45:57 AM         
   



> What is the best way to summarise data from a datetime field in SQL
>
> The dbf has, say, the following data in a datetime field :
>
> 01/01/08 12:01:00
> 01/01/08 2:00:00
> 02/01/08 1:05:00
> 03/01/08 5:01:00
>
> If I Select the dbf with GROUP BY, I get the 4 records, ie. the same as above.

With a FoxPro backend(?) you can use Cast()
CREATE CURSOR temp (test T)
INSERT INTO temp VALUES (DATETIME())
INSERT INTO temp VALUES (DATETIME()-3600)
BROWSE
SELECT distinct CAST(test As Date) as date__ from temp


> But, what I want is just the 3 dates, ie.
> 01/01/08
> 02/01/08
> 03/01/08
>
> 1. Is it possible to use GROUP BY to get the desired result ?

Yes (similar to the "Distinct" approach above).

> and
> 2. How do you get the date portion from the datetime field ?

You can use TToD()


hth
-Stefan

ENTIRE THREAD

SQL - Datetime field Posted by Phillip Bongers @ 7/11/2008 11:40:45 AM
RE: SQL - Datetime field Posted by Stefan Wuebbe @ 7/11/2008 11:45:57 AM
RE: SQL - Datetime field Posted by Phillip Bongers @ 7/11/2008 11:59:12 AM
RE: SQL - Datetime field Posted by Borislav Borissov @ 7/11/2008 11:47:34 AM
RE: SQL - Datetime field Posted by Phillip Bongers @ 7/11/2008 12:02:16 PM
RE: SQL - Datetime field Posted by Borislav Borissov @ 7/11/2008 12:21:55 PM
RE: SQL - Datetime field Posted by Phillip Bongers @ 7/12/2008 3:42:52 AM
RE: SQL - Datetime field Posted by Tanmoy Mukerji @ 7/12/2008 8:59:20 AM
RE: SQL - Datetime field Posted by Cetin Basoz @ 7/11/2008 1:27:28 PM