Click here to Skip to main content
15,891,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have date 12-4-1989 12:00:00 AM in my database I want to display only DD-MM part of the date on the page is ther any convert date function to reterive this format.

is any other way to achive this...

any one know kindly help me plz...
Posted
Updated 17-Apr-12 19:56pm
v2

You can do this both in SQL Server or in the ASP.Net C# code.

In C# ->
C#
String format = "dd-MM";
String dateStr = date.ToString(format);


In SQL Server ->
SQL
SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) AS [DD MM]
 
Share this answer
 
v2
Comments
member60 18-Apr-12 2:13am    
my 5!
Abhinav S 18-Apr-12 2:21am    
Thanks.
Reza Ahmadi 18-Apr-12 2:29am    
5!
Abhinav S 18-Apr-12 2:31am    
Thanks.
Try
SQL
select convert(varchar(5), getdate(), 105)

this assumes that you have a date to start with, by replacing getdate() with your column you will get dd-mm.
 
Share this answer
 
Hi,
See the code below:

C#
DateTime dt = Convert.ToDateTime("12-4-1989 12:00:00 AM"); //Coming from your DB, I have hardcoded here
 string dt1 = String.Format("{0:dd-MM}", dt);



Now, Use the dt1 as you want....
 
Share this answer
 
Comments
Manojkushwaha 18-Apr-12 2:44am    
Hi,
I used this one but it returns 12/4/1989
Vipin_Arora 18-Apr-12 12:41pm    
well its working fine for me.
dt1 must get the value:04-12

For testing, u can try this code on a button click, show the value of dt1 in messagebox. u will definitely got : 04-12

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