Skip to content

Converting a DateTime Field in SQL to NVARCHAR

January 22, 2014

Because MS SQL doesn’t automatically convert a DateTime field in a useful format in CSV. A useful solution to get around this is to use this function SELECT CONVERT(VARCHAR(20), GETDATE(), 100). It converts a datetime field in the format  Mon DD YYYY 1
HH:MIAM (or PM) e.g. Jan 1 2005 1:29PM 1

1 To make the month name in upper case, simply use the UPPER string function.

You can do this for a data column like so SELECT CONVERT(VARCHAR(20), [ColumnName], 100)

Hope that helps!

 

Advertisements

From → Uncategorized

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: