Saturday, 30 November 2013

 This value is derived from the operating system of the computer on which the instance of SQL Server is running.
SELECT GETDATE() as TODAY
Ans:
DATEPART():
It returns the part of the date like YEAR,MONTH,WEEK,DAY,QUARTER,DAYOFYEAR,WEEKDAY,HOUR,MINUTE
,SECOND and MILLISECOND



 DATEDIFF():
Returns the count of the specified datepart boundaries crossed between the specified startdate and enddate.
ex:
SELECT DATEDIFF(YEAR,HIREDATE,GETDATE())AS DIFFERENCE FROM EMP


SELECT DATENAME(DAY, '2007-06-01')as dayinmonth,DATENAME(DY, '2007-06-01')as dayinyear,DATENAME(WEEKDAY, '2007-06-01')as weekday;
ans:
DAY():
Returns an integer representing the day (day of the month) of the specified date.
Ex:
SELECT DAY(GETDATE())AS DAYOFMONTH

MONTH():
SELECT MONTH(GETDATE())AS MONTHOFYEAR

YEAR():
SELECT YEAR(GETDATE())AS YEAR

CONVERSIONS
note:conversions are collected from different websites
declare @date datetime

set @date='2012-03-16 '

SELECT convert(varchar, @date, 103)

 

No comments:

Post a Comment

EMP, DEPT Sample script

/****** Object:  Table [dbo].[DEPT]    Script Date: 19-05-2016 06:58:37 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET A...