Click here to Skip to main content
15,883,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i convert
19-jan-12 11:12:12 PM to 19-jan-12


i store datetime in SqlServer Database

it stored as "19-jan-12 11:12:12 PM" format
now i want to get row whose date is 19-jan-12
and bind that data so how can i check from database

please help quickly

thnx
Posted
Comments
You should mention whether you want to do it in code or with query???
The way you asked the question it conveys that you want to do it with SQL Query itself...
You could have commented us that you wanted the coding not query, but giving a poor rating for that is not the wise thing to do....
PKriyshnA 20-Jan-12 9:33am    
i have a table named Tbl_Product
having columns (id,PName,PTime)----

(1,Nokia,1/20/2012 7:02:09 PM)
(2,Samsung,1/21/2012 7:02:09 PM)
(3,Micromax,1/20/2012 7:02:09 PM)
(4,Tablet,1/21/2012 7:02:09 PM)
(5,Pendrive,1/20/2012 7:02:09 PM)
now i want to select data in a such manner date shoud be 1/20/2012

compare only 1/20/2012 and bind it to GridView.......help me....

SQL
SELECT convert(varchar, getdate(), 100) – mon dd yyyy hh:mmAM (or PM)

                                        – Oct  2 2008 11:01AM

SELECT convert(varchar, getdate(), 101) – mm/dd/yyyy - 10/02/2008

SELECT convert(varchar, getdate(), 102) – yyyy.mm.dd – 2008.10.02

SELECT convert(varchar, getdate(), 103) – dd/mm/yyyy

SELECT convert(varchar, getdate(), 104) – dd.mm.yyyy

SELECT convert(varchar, getdate(), 105) – dd-mm-yyyy

SELECT convert(varchar, getdate(), 106) – dd mon yyyy

SELECT convert(varchar, getdate(), 107) – mon dd, yyyy

SELECT convert(varchar, getdate(), 108) – hh:mm:ss

SELECT convert(varchar, getdate(), 109) – mon dd yyyy hh:mm:ss:mmmAM (or PM)

                                        – Oct  2 2008 11:02:44:013AM

SELECT convert(varchar, getdate(), 110) – mm-dd-yyyy

SELECT convert(varchar, getdate(), 111) – yyyy/mm/dd

SELECT convert(varchar, getdate(), 112) – yyyymmdd

SELECT convert(varchar, getdate(), 113) – dd mon yyyy hh:mm:ss:mmm

                                        – 02 Oct 2008 11:02:07:577

SELECT convert(varchar, getdate(), 114) – hh:mm:ss:mmm(24h)

SELECT convert(varchar, getdate(), 120) – yyyy-mm-dd hh:mm:ss(24h)

SELECT convert(varchar, getdate(), 121) – yyyy-mm-dd hh:mm:ss.mmm

SELECT convert(varchar, getdate(), 126) – yyyy-mm-ddThh:mm:ss.mmm
 
Share this answer
 
1) string strDate = System.DateTime.Now.ToShortDateString("dd-MM-yy");
2) string strDate = System.DateTime.Now.ToShortDateString();
3) string strTime = System.DateTime.Now.ToShortTimeString();
 
Share this answer
 
v2
string.Format("{0:dd-mm-yyyy}", DateTime.Now);
 
Share this answer
 
C#
Select Convert(varchar(11),DateofBirth,106)as DateofBirth
 
Share this answer
 
try this
SELECT CONVERT(VARCHAR(10), getdate(), 105) AS [DD-MM-YYYY]
 
Share this answer
 
Use convert function:

When selecting in sql server itself select as like this
"CONVERT(DATE,GETDATE(),101)"

Convert(DataType,Feildname,formattype)


Refer format type in :msdn Link
 
Share this answer
 
v3
TextBox1.Text = DateTime.Now.ToString("dd-MM-yy");
 
Share this answer
 
Your required answer is -

select convert(varchar(12), CreatedOn, 106) date from Test
 
Share this answer
 
If you want to determine the date part of a SQL datetime value in SQL, the following code is an efficient way to do it:

SQL
print convert(datetime, floor(convert(float, getdate())))
 
Share this answer
 
you can use

C#
dateToDisplay.ToShortDateString()


NOTE : The string returned by the ToShortDateString method is culture-sensitive. It reflects the pattern defined by the current culture's DateTimeFormatInfo object. For example, for the en-US culture, the standard short date pattern is "M/d/yyyy"; for the de-DE culture, it is "dd.MM.yyyy"; for the ja-JP culture, it is "yyyy/M/d". The specific format string on a particular computer can also be customized so that it differs from the standard short date format string.

ref : http://msdn.microsoft.com/en-us/library/system.datetime.toshortdatestring.aspx[^]
 
Share this answer
 
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900