Monday, 13 May 2013

Sql Date only,month only,Year only using DateTime,DatePart

Sql  Date only,month only,Year only using DateTime,DatePart

// Create
 Create Table Char_Index

   (
ID Int Identity(1,1),
LastDate DateTime,
Title varchar(MAX),
Content Varchar(MAX),
    ) 

 // Insert:
Insert Into Char_Index(LastDate,Title,COntent) Values(GETDATE(),'Google','Indian version of this popular search engine. Search the whole web or only webpages from India.<img src="http://www.google.co.in/images/srpr/logo4w.png" />Interfaces offered in English, Hindi, Bengali, Telugu, Marathi ...')

Insert Into Char_Index(LastDate,Title,COntent) Values(GETDATE(),'Gmail','Google New to Gmail? Create an account. Sign in. Username ... <img src="http://www.google.co.in/images/srpr/gmail.png" />Experience the ease and simplicity of Gmail, everywhere you go. About Gmail - email from')

//Select
      Select * From Char_Index
   

  // DATEPART()

      Select DATEPART(DAY,LastDate) as Date,DATEPART(MONTH,LastDate)as         
          mon,DATEPART(year,LastDate) as Year From Char_Index
 

 // DATENAME()

     Select DATENAME DAY,LastDate) as Date,DATENAME(MONTH,LastDate)  
           as  mon,DATENAME(year,LastDate) as Year From Char_Index


No comments:

Post a Comment