March 12, 2009 at 9:17 am
hi,
Can you help me how to extract the day,month,year from a data saved in a database.
For example 2/4/2009 is in a database, What code or command should i use to extract the day, month and year from the data.
thanks
March 12, 2009 at 9:24 am
You want to use the datepart function. You can look it up in BOL for all the permutations, but it basically works like this:
SELECT DATENAME(yyyy,'3/12/2009') AS 'Year'
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
March 12, 2009 at 9:34 am
Grant Fritchey (3/12/2009)
You want to use the datepart function. You can look it up in BOL for all the permutations, but it basically works like this:
SELECT DATENAME(yyyy,'3/12/2009') AS 'Year'
Or:
declare @ADate datetime;
set @ADate = '2009-03-12';
select YEAR(@ADate), MONTH(@ADate), DAY(@ADate)
Again, look these up in BOL as well.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply