Showing posts with label date-time. Show all posts
Showing posts with label date-time. Show all posts

Thursday, March 29, 2012

Converting Date-Time to Date Conundrum

I need to be able to convert a Date-Time Field to a Date Fied in my SQL
Tables.
Using CONVERT (varchar, "Date-Time Field", 103) gives me the correct result
but because it converts the date value to a string I can say goodbye to
localization.... any ideas on how to convert the field but still allow
localization.Try this function...
CREATE FUNCTION [dbo].[fnRemoveTimeFromDateTime] (@.InputDate DATETIME)
RETURNS DATETIME AS
BEGIN
DECLARE @.OUTPUT AS SMALLDATETIME
SET @.OUTPUT = CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, @.InputDate)))
RETURN @.OUTPUT
END
"SAcanuck" wrote:
> I need to be able to convert a Date-Time Field to a Date Fied in my SQL
> Tables.
> Using CONVERT (varchar, "Date-Time Field", 103) gives me the correct result
> but because it converts the date value to a string I can say goodbye to
> localization.... any ideas on how to convert the field but still allow
> localization.

Converting Date-Time to Date

Hi: I am new to Reporting Services.
My issue is that I have a Date-Time Field which I want to use as a column heading for a crosstab. However since there are multiple date entries with varying times I get multiple column headings. Could anyone tell me how to convert this datetime field to a date field so that I only get one column per day.
ThanksThere are are number of VB.Net functions for manipulating dates which you
could use for this.
The simplest (but probably not most efficient) way would be to convert the
date to a string then back to a date: =CDate(CStr(Fields!DateTime.Value))
You might want to consider doing the conversion in your query instead.
--
My employer's lawyers require me to say:
"This posting is provided 'AS IS' with no warranties, and confers no
rights."
"SAcanuck" <SAcanuck@.discussions.microsoft.com> wrote in message
news:F6AFC614-180B-4C75-94B8-DB3149275D3D@.microsoft.com...
> Hi: I am new to Reporting Services.
> My issue is that I have a Date-Time Field which I want to use as a column
heading for a crosstab. However since there are multiple date entries with
varying times I get multiple column headings. Could anyone tell me how to
convert this datetime field to a date field so that I only get one column
per day.
> Thanks

Sunday, February 12, 2012

Convert Date-Time Field to Date

Using Query Analyzer and a select statement, how do you
convert a date-time field to a date field?
Thanks
There is no date-only datatype in SQL Server. Both DATETIME and
SMALLDATETIME have time components. What I think you want to do is format
your DATETIME data as a string?
You can use CONVERT and apply a style. Look up all of the styles in BOL.
Here's an example, using style 107:
SELECT CONVERT(CHAR(12), GETDATE(), 107) AS FormattedDate
"Charles Allen" <callen@.bkd.com> wrote in message
news:2cc7c01c46916$63b21a30$a301280a@.phx.gbl...
> Using Query Analyzer and a select statement, how do you
> convert a date-time field to a date field?
> Thanks
|||Thank you for the incredibly quick reply.

>--Original Message--
>There is no date-only datatype in SQL Server. Both
DATETIME and
>SMALLDATETIME have time components. What I think you
want to do is format
>your DATETIME data as a string?
>You can use CONVERT and apply a style. Look up all of
the styles in BOL.
>Here's an example, using style 107:
>
>SELECT CONVERT(CHAR(12), GETDATE(), 107) AS FormattedDate
>
>"Charles Allen" <callen@.bkd.com> wrote in message
>news:2cc7c01c46916$63b21a30$a301280a@.phx.gbl...
>
>.
>