Article View: borland.public.interbase.sql
Article #1033Re: Round a DateTime
From: Svein Erling Tysvær
Date: Mon, 19 Mar 2007 10:04
Date: Mon, 19 Mar 2007 10:04
36 lines
1977 bytes
1977 bytes
Robin wrote:
> Hi everyone,
>
> I want to count distinct days in a period from a datetime field. I am
> surprised by how difficult I have found this.
>
> My problem is in getting the date part of a datetime in SQL.
>
> Is there a way to truncate a datetime to just a date?
>
> I thought trunc or frac, but they are not available. I can't seem to
> cast the datetime as an integer either.
>
> The only way I have found is to cast the datetime as varchar(11) which
> happens to return only the date part. Then cast THAT as an integer.
>
> Which /appears/ to work, but makes me feel dirty ;-)
>
> I am using Interbase6.x/FB1.5. I am unable to make stored procedures,
> UDF etc so I need to do it in raw SQL only.
>
> Any ideas?
>
> Thanks in advance.
Why not simply
CAST(MyDateTimeField as Date)
select cast(cast('19.03.2007 14:25:23:8532' as Timestamp) as Date)
from rdb$database
works for me (tested in Fb 1.5. I do not have IB 6.x, but it ought to be
similar).
Set
Technical Details
Message-ID:
<45fe6022@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45fe1225@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,cf698e5e2a79f5a0 X-Google-Attributes: gid114a0e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Mon, 19 Mar 2007 11:04:18 +0100 From: Svein Erling Tysvær <svein.erling.tysvaer@kreftregisteret.no> User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 Newsgroups: borland.public.interbase.sql Subject: Re: Round a DateTime References: <45fe1225@newsgroups.borland.com> In-Reply-To: <45fe1225@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 84.49.7.130 Message-ID: <45fe6022@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1174298658 84.49.7.130 (19 Mar 2007 03:04:18 -0800) Lines: 36 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail