Wednesday, May 8, 2013

date time format in sql server

Question  1 : 

How to get current date time in sql server?

Ans :      
      
  SELECT GETDATE()

Question 2:   How to get Only Date from  datetime  in sql server ?

Ans :

SELECT
CONVERT(VARCHAR(8),GETDATE(),108) AS HourMinuteSecond,
CONVERT(VARCHAR,GETDATE(),101) AS DateOnly(MM/dd/yyyy),
CONVERT(VARCHAR,GETDATE(),103) AS DateOnly(dd/mm/yyyy),
CONVERT(VARCHAR,GETDATE(),105) AS DateOnly(dd-mm-yyyy);


Question 3 :    How to add  minutes,hour,day  in specific Date  in sql server

Ans :

 we can do this using DATEADD function .

Syntax :

DATEADD (datepart , number , date )

Example :

select DATEADD (hour , 1 ,getdate()) as Addhour,

DATEADD (month , 1 , getdate()) as Addmonth,

DATEADD (minute , 1 , getdate()) as Addminute,

DATEADD (day , 1 , getdate()) as Addminute




Question 4 :    How to get YearMonth  Date Format in  sql server 

Ans :

Select  left(convert(varchar,getdate(),112),6)

Output

201305

If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website

0 comments:

Post a Comment