Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friend

i bind a date in datalist but i get a result like this 03/04/2013 00:00:00 but i want like 03/04/2013 no time.
i applied this one:
ASP.NET
" <asp:Label ID="lbldate" runat="server" style="background:none; padding:0; margin:0" Text='<%#  Eval("_News_Date", "{0:dd/MM/yyyy}") %>' >"

but when i applied in code behind like this
C#
convert(char,_News_Date,103) as _News_Date

then i facing a problem,is that dates are not come asc order.

so can you tell me how to get date in dd/mm/yyyy format without time
Posted
Updated 3-Apr-13 7:04am
v2

Hi Rohit,

You can also use this option.

<asp:Label ID="lblDate" runat="server" Text='<%# Convert.ToDateTime(Eval("_News_Date")).ToString("dd/MM/yyyy") %>'></asp:Label>
 
Share this answer
 
Comments
Rohit Sharma706 4-Apr-13 0:54am    
thank u very much...its work
The idea is to convert date as string[^] and then to bind it to your label:
SQL
DECLARE @myDate DATETIME

SET @myDate = '2013/03/29'

SELECT @myDate AS MyDate
--returns: 2013/03/29 00:00:00.000

SELECT CONVERT(NVARCHAR(10), @myDate, 103) AS MyDate
--returns: 29/03/2013
 
Share this answer
 
Query should be like this
SQL
select convert(char,_News_Date,103) as _News_Date 
From tbl 
Order by _News_Date asc

Happy Coding!
:)
 
Share this answer
 
C#
<asp:Label ID="lbldate" runat="server" Text='<%# formatDate(Eval("new_date","{0:MM/dd/yyyy}"))%>'></asp:Label>




C#
protected string formatDate(string date)
        {
            if (date == null || date == "1/1/0001")
            {
                return "";
            }
            else
            {
                return date;
            }
        }
 
Share this answer
 
v3
Convert date to string and then try binding

DateTime dt = DateTime.Now;
var dts = dt.ToShortDateString();
 
Share this answer
 
DateTime date = (DateTime.Now).ToString("yyyy/M/d"));

Hope this will help you
 
Share this answer
 
Hi
Use ToShortDateString() method. it will return mm/dd/yyyy not time.
 
Share this answer
 
i have better option for u.

while u bind the data if u using sql server then used

Select (Convert(Char(10),GetDate(),103)) As CurrentDate

Put your date behalf of GetDate()
 
Share this answer
 

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