StumbleUpon
Share on Facebook

Monday, April 16, 2007

Formatting Date Input - DateFOrmat

Formatting Date Input - Jan-7 or July 1 / British Way of Date Representation / British Date


DECLARE @datevar DATETIME;
SET @datevar = '01/07/2006';
SELECT @datevar AS DateVar;
SELECT datename(month, @datevar) AS month_name;
The above will return January

SET @datevar = '07/01/2006';
SELECT @datevar AS DateVar;
SELECT datename(month, @datevar) AS month_name;
The above will return July

If you are using British way of representing dates, then '01/07/2006' is 1-July. Use dateformat to change the input to dmy system
Set DateFOrmat dmy;
GO
DECLARE @datevar DATETIME;
SET @datevar = '01/07/2006';
SELECT @datevar AS DateVar;
SELECT datename(month, @datevar) AS month_name;
The above will return July

DECLARE @datevar DATETIME;
SET @datevar = '07/01/2006';
SELECT @datevar AS DateVar;
SELECT datename(month, @datevar) AS month_name;
The above will return Jan

DateFOrmat does not affect the display of date values

No comments:

Related Posts Plugin for WordPress, Blogger...