Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Query to get only date from datetime in sql server like dd/mm/yyyy, mm/dd/yyyy, yyyymmdd, dd-mm-yyyy etc

Nov 23, 2010
Introduction

Here I will explain how to convert or get only date from datetime in different formats like like dd/mm/yyyy, mm/dd/yyyy, yyyymmdd, dd-mm-yyyy etc in SQL Server.

Description

In many situations I got requirement like changing datetime to date and changing the date format to different ways like dd/mm/yyyy or mm/dd/yyyy or dd.mm.yy or yy.mm.dd. We can covert our datetime to date with different formats using different styles. I will display different format of dates with samples check it 


DECLARE @DateTime DATETIME

SELECT @DateTime = '2010/05/20 11:21:13'

/*For mm/dd/yyyy format*/
Select CONVERT(VARCHAR(10),@DateTime ,101) as Date








/*For yyyy.mm.dd format*/
Select CONVERT(VARCHAR(10),@DateTime ,102) as Date








/*For dd/mm/yyyy format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,103) AS Date








/*For dd.mm.yyyy format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,104) AS Date








/*For dd-mm-yyyy format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,105) AS Date








/*For hh:mi:ss format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,108) AS Date








/*For mm-dd-yyyy format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,110) AS Date








/*For yyyy/mm/dd format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,111) AS Date








/*For yyyymmdd format*/
SELECT CONVERT(VARCHAR(10),@DateTime ,112) AS Date



If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

11 comments :

Anonymous said...

Nice Blog

dotnetinfomedia said...

its very useful....

Keep rocking Mr.Suresh...


Regards,
Balaji.J
http://dotnetinfomedia.blogspot.com/

Anonymous said...

Very helpful

madhubabuchinnam said...

nice one........

Anonymous said...

hey, suresh very nice for ur solution i need a small help from u hope u will help me ...

in asp.net when ever i m inserting gregorian date its showing hijri date in report.

thnks in advance?

Anonymous said...

Very helpful sir
just assume...

I had lots time waste for it
again thanks to share this aretical

Anonymous said...

ur posts are always helpful

Anonymous said...

thanks

KUM said...

You are better than the MSDN.

Anonymous said...

if you cheng date the query will not work

Rohan Kota said...

Thanks Man..Suresh..!

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.