Share this with your friends 

undocumented Date Function

8 ratings Views 713 
Author: TEJINDER (TEJINDER SINGH)  View Profile |  View other solutions by this author

Question / Problem

extract different part of datetime


/*return only date*/
select {fn current_date()}
/*Return only time*/
select {fn current_time()}
/*Return Datetime*/
select {fn now()}
/*Return hour*/
select {fn extract(hour from getdate())}
/*Return Minute*/
select {fn extract(minute from getdate())}
/*Return Second*/
select {fn extract(second from getdate())}
/*Return Day*/
select {fn extract(day from getdate())}
/*Return Month*/
select {fn extract(month from getdate())}
/*Return Year*/
select {fn extract(year from getdate())}
/*Return DayName*/
select {fn dayname(GetDate())}
/*Return MonthName*/
select {fn monthname(GetDate())}
/*return Month Number*/
select {fn month(GetDate())}
/*Return Year*/
select {fn year(GetDate())}

Applies to

Microsoft SQL Server 2005

Rank It

Login to rank it