You are here: Re: Informix Date Function Equivalent « MsSQL Server « IT news, forums, messages
Re: Informix Date Function Equivalent

Posted by Ross Presser on 05/21/05 01:23

On 20 May 2005 10:06:37 -0700, Matt wrote:

> The DATE function takes as input a non-DATE value such as CHAR,
> DATETIME, or INTEGER and returns the corresponding DATE value.

The equivalent of this would be CONVERT:

convert(datetime,'2005-05-14')

But you'd still need dateadd/datediff to do the date arithmetic.

One of the interesting, if convoluted, uses for convert with dates is to
group by an unusual time period. For instance, this would produce a summary
by 6-hour shifts:

SELECT ShiftStart, count(*)
FROM (
SELECT convert(datetime,
floor(convert(float, EntryTime) * 4) / 4) as ShiftStart
FROM Entries
WHERE EntryTime IS NOT NULL
) AS RoundedEntries
GROUP BY ShiftStart
ORDER BY ShiftStart

I tried using 3 instead of 4, but ran into rounding errors: instead of
16:00:00 I was getting 15:59:59.997.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация