Wednesday, May 23, 2007

Some Date time Facts in sql server

How to convert Datetime to only time
select CONVERT(VARCHAR(10), GETDATE(),101)

It will convert the date into varchar in mm/dd/yyyy format.

select CONVERT(VARCHAR(10), GETDATE(),103)
It will convert date in to varchar in dd/mm/yyyy format.

How to convert Datetime in format date and time 00.00.00

select convert(datetime, convert(varchar, getdate(), 101))

How to find Date difference
Use DATEDIFF(d, startdate, endddate) to return the number of day
DATEDIFF(yy, startdate, endddate) to return the number of year
DATEDIFF(m, startdate, endddate) to return the number of months


Convert datetime to String, suppose if u want to compare
select CONVERT(VARCHAR(10), GETDATE(),112)

convert datetime to string in format yyyymmdd,
09/05/2006 = 20060905
02/06/2007 = 20070206

Sleepy sleepy..............

Time to sleep....
Enjoy.....

Any other query regarding this, reply to the post.

No comments: