SQL Server Date Processing

This post is a blatant link post about an issue I was having with SQL Server 2005 when writing T-SQL queries that needed to display dates based on the current connection’s language, in summary when writing queries always express explicit dates as ‘yyyy-mm-ddT00:00:00’ omitting the T or omitting the time will make the date language ambiguous. (I was using ‘yyyy-mm-dd’ thinking this was explicit)

Thanks to Jamie Thomson for posting this.

Truncating Dates

I find it useful to be able to truncate dates to a specific level, this is done like so:


The above SQL statement gets the current UTC date rounded to the day, just change the two day intervals to minute or whatever to truncate to smaller values.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: