• [font="Verdana"]Okay, I thought about the code you posted some more, and I suspect that your originating date is actually stored as an integer in the form:

    YYYYMMDDHHMMSS

    That explains why you would need this bit of code:

    cast(stuff(stuff(stuff(cast(CREATED_AT as varchar(17)), 9, 0, ' '), 12, 0, ':'), 15, 0, ':') as datetime)

    That takes the integer, converts it to a string, adds in the necessary formatting characters, and converts the result to a datetime.

    In which case, you might want to try something like the following:

    declare @x table(

    CREATED_AT bigint not null

    );

    insert into @x values(20090717102705);

    select

    1

    , CRM_Orders.CREATED_AT as [Service Order Created At]

    , dateadd(month, datediff(month, 0, CRM_Orders.CREATED_AT), 0) as [Service Order Created At Month]

    from (

    select cast(stuff(stuff(stuff(cast(CREATED_AT as varchar(17)), 9, 0, ' '), 12, 0, ':'), 15, 0, ':') as datetime) as CREATED_AT

    from @x

    ) CRM_Orders;

    What I have done is created a sub-select that does the date conversion once. Thereafter I can just treat it as a date (so I don't have to do the conversion every time I want to use it.)

    Also, my apologies. If this is what you are doing, then the date conversions you were doing are fine. That's SQL Server's standard date format, and your code would work correctly regardless of the default date format.

    [/font]