Stripping time out of datetime in SQL Server 2005

    Date: 05/11/09 (SQL Server)    Keywords: no keywords

    SELECT CAST(CAST(getdate() as int) as datetime)

    Avoids messing about with strings :)

    And then, to get the start of the current month...

    SELECT CAST(CAST(DATEADD(DAY,DATEPART(DAY,getdate())*-1, getdate()) as int) as datetime);

    This I am using for daily Month-To-Date reporting. Comparison is much faster this way than checking DatePart(Month,getdate()) and DatePart(Year,getdate()) against the column.

    Source: https://sqlserver.livejournal.com/70837.html

« Data warehouse community || It's the newest post


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home