Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 19-Jan-12 21:59pm
PKriyshnA1.6K
Comments
Tadit Dash at 20-Jan-12 7:02am
   
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 at 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....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

TextBox1.Text = DateTime.Now.ToString("dd-MM-yy");
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

you can use
 
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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

Select Convert(varchar(11),DateofBirth,106)as DateofBirth
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

string.Format("{0:dd-mm-yyyy}", DateTime.Now);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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:
 
print convert(datetime, floor(convert(float, getdate())))
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Your required answer is -
 
select convert(varchar(12), CreatedOn, 106) date from Test
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

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
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

try this
SELECT CONVERT(VARCHAR(10), getdate(), 105) AS [DD-MM-YYYY]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 11

1) string strDate = System.DateTime.Now.ToShortDateString("dd-MM-yy");
2) string strDate = System.DateTime.Now.ToShortDateString();
3) string strTime = System.DateTime.Now.ToShortTimeString();
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 186
4 Aajmot Sk 153
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 20 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100