How to display "dd-mm-yyyy" format from database to text box ?


How to display "dd-mm-yyyy" format from database to text box ? i have written like this but i m not getting the expected op.

txtDate.Text= string.Format(ds.Tables[0].Rows[0]["NewsDate"].ToString(),"dd-mm-yyyy");

Chandra Dev
4/20/2009 11:04:02 AM 93655 articles. 6 followers. Follow

13 Replies

Similar Articles

[PageSpeed] 53

4/20/2009 11:20:18 AM

Try like this:

txtDate.Text= ds.Tables[0].Rows[0]["NewsDate"].ToString("dd-MM-yyyy");

By the way, I advise that you check for nulls, prior to doing this, just to be safe (especially is NewsDate fields can be null).

C# <---> VB.Net Translator
4/20/2009 11:22:21 AM

txtDate.Text= string.Format(ds.Tables[0].Rows[0]["NewsDate"].ToString(),"dd-mm-yyyy");

 try which format as you need

select convert(varchar,getdate(),101)
OutPut:- 06/18/2008

select convert(varchar,getdate(),102)
OutPut:- 2008.06.18

select convert(varchar,getdate(),103)
OutPut:- 18/06/2008

select convert(varchar,getdate(),104)
OutPut:- 18.06.2008

select convert(varchar,getdate(),105)
OutPut:- 18-06-2008

select convert(varchar,getdate(),106)
OutPut:- 18 Jun 2008

select convert(varchar,getdate(),107)
OutPut:- Jun 18, 2008

select convert(varchar,getdate(),108)
OutPut:- 10:53:20

select convert(varchar,getdate(),109)
OutPut:- Jun 18 2008 10:53:30:507AM

select convert(varchar,getdate(),110)
OutPut:- 06-18-2008

select convert(varchar,getdate(),111)
OutPut:- 2008/06/18

select convert(varchar,getdate(),112)
OutPut:- 20080618

select convert(varchar,getdate(),113)
OutPut:- 18 Jun 2008 10:54:01:253

select convert(varchar,getdate(),114)
OutPut:- 10:54:08:473

select convert(varchar,getdate(),120))
OutPut:- 2008-06-18 10:54:15

My Blog :

Please remember to click “Mark as Answer” on the post that helps you,and to click “Unmark as Answer” if a marked post does not actually answer your question.
4/20/2009 11:23:30 AM



Please remember to click "Mark as Answer" on the post that helps you.
4/20/2009 11:23:32 AM

Hi, Try This -

String.Format("{0: dd/MM/yyyy}", Value))


Best Of Luck .........
4/20/2009 12:06:44 PM

Hi Friend,,


    In VB.NET you can use




4/21/2009 11:29:00 AM

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"

CodeFile="abc.aspx.cs" Inherits="abc" Title="abc"

Culture="en-GB" StylesheetTheme="Default" %>


Add Culture="en-GB" in page directive .... if culture is en-GB then the format will b dd/MM/yyy and if it US then the format will be mm/dd/yyy

4/21/2009 11:52:51 AM


could you tell me the syntax for displaying dd/mm/yyyy with exact time.? like forum datetime.

Chandra Dev
5/4/2009 6:36:00 AM

format(,"dd-MM-yyyy ss:mm:hhhh"

Neha J.
5/4/2009 6:42:41 AM

Hi Chandra Dev,

When you store in to the database table you should store date and time as well.

If you are adding from frontend then use now() function to add data and time in the table.

Try this


dd-MM-yyyy ss:mm:hhhh tt





Mark as answer if this post helpfull to you.

Don't be afraid to be wrong; otherwise you'll never be right.
5/4/2009 7:05:26 AM


Thanks for sending good reply. I have one more question. I know to display dd-MM-yyyy using BoundField. But i have to display using templete field on  label.

I m trying like this. But it is not giving the expected op.

<asp:Label ID="label3" Text='<%#Eval Format("Posted_Date",'dd-MM-yyyy')%>' runat="server"></asp:Label>


Chandra Dev
5/4/2009 9:27:51 AM


I m trying like this. But it is not giving the expected op.

<asp:Label ID="label3" Text='<%#Eval Format("Posted_Date",'dd-MM-yyyy')%>' runat="server"></asp:Label>


try this 

<asp:TextBox id="txtCloseDate" Text='<%# Eval("CloseDate","{0:dd/MM/yy}") %>' runat="server" />

My Blog :

Please remember to click “Mark as Answer” on the post that helps you,and to click “Unmark as Answer” if a marked post does not actually answer your question.
5/4/2009 9:34:00 AM

Thanks friend. I have one more question.I have to display news using gridview and there i want to display time on label control like forum "1hr 10 min ago". How to do  this one ?

Chandra Dev
5/4/2009 10:56:55 AM

Similar Artilces:

how can i convert the string from "21/12/2005" which is in dd/MM/yyyy format to MM/dd/yyyy
hi all i would like to convert a string that is when user type in the textbox let say "21/12/2005" in dd/MM/yyy and convert to MM/dd/yyyy . how do it do that ?Karen Dim dt As DateTime = txtInput.Text txtOutput.Text = dt.ToString("MM/dd/yyyy")think this should do it Dim strDate(3) as String Dim strDateNewFormat as String strDate = txtDate.text.split("/"c) strDateNewFormat = strDate(1) & "/" & strDate(0) & "/" & strDate(2) ThanksDinuj Nath Try this link for sample code.  Hope this helps.

MaskedEditExtender date format problem ("yyyy-MM-dd" with cultureName="sv-SE" doesn't work)
Hi All, I need to create MaskedEditExtender for Sweden date which uses format "yyyy-MM-dd". I have the following code below. CalendarExtender doesn't work with current MaskedEditExtender. Also the validation doesn't work properly. <asp:TextBox ID="txtFSFV" MaxLength="100" style="width:70px" runat="server" /> <asp:HyperLink ID="hplGetCalendar" NavigateUrl="javascript:void(null)" runat="server"> <img src="~/images/calendar.png" runat...

Check if the text box "text" has changed (RePost from web forms forum)
Greetings! How can i know if the "text" inside of a text box has changed? For example, I currently have this: if (txtMU.TextChanged()) { } But this does not work. The other idea I had was to assign the existing value of the text box to a string and then when the user click the save button I can create a conditional statement to compare the original string with the new string. However, I would like something more effective as I have like 12 text boxes to compare. Thanks, EduardoThanks,Please Mark this post as answered if it was helpful. Here is the easiest way that I have ...

Display "Text" for "Values" retrieved from Database table
For my form dropdownlists I save the "Values" (not the TEXT that displays) for the selected item to the SQL database.  The problem now is when I want to display the data that I retrieve from a query, I want to show the actual "Text" associated with that value and not the Value that was stored.  I am displaying the data in a datagrid with the syntax, e.g. <asp:label Runat="server" ID="TestID" Text='<%# Container.DataItem("TestID") %>'  ForeColor="#ffffff" BackColor="#6699CC" Font-B...

DataFormatString="{0:dd-MM-yyyy HH:mm}" not displaying military time on remote server
I have a boundfield as follows: <asp:BoundField DataField="PAStatusDate" DataFormatString="{0:dd-MM-yyyy HH:mm}" HeaderText="PA Status Date" HtmlEncode="False" /> When I build this app on my local PC the time portion correctly displays in military time, ie 15:32.When I run this code on my remote server, the time is displayed as 03:32.I have tested variations using h, hh, H, HH and in all instances the remote server displays 3:32 (either with/without leading zero).I tried changing the regional settings on the server to use format ...

save date in database n retrieve with format dd\mm\yyyy not mm\dd\yyyy display to main.aspx
I need input from user using text box which is like this dd mm yyyy and how can i manipulate so that i can save in db with default format mm dd yyyy? HI, you can use the format method of the textbox and specify the date format in that. I havent tried but it should work. Have a Great DayRegardsRamu can u provide me with example so that i can see clearly what ur point...tq Hi, If possible ask the user to enter the date in dd-mmm-yyyy fromat so that, there won't be any confusion between month and date when you save your record in db. otherwise, you can use format functi...

Calendar extender format="dd.MM.yyyy"?
 Hi. I have one question about date format in ajax toolkit calendar extender. I want to set the format to "dd.MM.yyyy" because thats the format I need to insert into database. Here is my test code: <%@ Page Language="C#" MasterPageFile="~/master.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="test" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><asp:Content ID="Content1" ...

format Date field in Dataset to "mm/dd/yyyy"
Currently I have a query that is populating a dataset with a date value. Here is my code:  With cmd .CommandText = "SELECT pEff_Dt FROM MyTable WHERE condition1 = condition2" .Parameters.Add(BMItemno) .Connection = SQLConn .CommandType = CommandType.Text End With adapter.SelectCommand = cmd adapter.Fill(dsEffDate) How can I access the only date field passed to my dataset (pEff_Dt) and format it to "mm/dd/yyyy"? Currently is formated to Sat Sep 30 16:31:33 PDT 2006 Any suggestions?  Victor A. Pa...

How to validate date time format must be "yyyy/mm/dd"?
I use VS2003 , C# In my Layout have a TextBox for user to input Publish Datethe date time format must as "yyyy/mm/dd"layout like belowPublish Date | TextBox |   ex:2008/09/22but sometimes user just input 20080922 or 97/09/22 and so to validate this TextBox must as "yyyy/mm/dd"?thank you very much you can accept the date as long as it is valid, and then convert it to whatever format you want. Here are 2 options to validate Date 1) The CompareValidator is an option, use Operator=DataTypeCheck and Type=Date for Validator 2) RegularExpression...

How to convert format of a DateTime object to "yyyy-MM-dd" style
Hi all, i have a date in string data type. i m using Convert.ToDateTime function to convert this string date to DateTime object. When i get this date as a DateTime object it is in "dd-MM-yyyy" format. but i want to convert its format to "yyyy-MM-dd". Can anyone tell me how to convert the format of a DateTime object. I don't want the format with string data type. Please help me. Thanks in advance. once you got your object just do a .ToString("yyyy-MM-dd") on the end of it. Otherwise you'll probably have to change your server settings to be that f...

how to get date in "dd/mm/yyyy" using
Hi I have  textbox, while page loads, by default this texbox need to be with today's date in "dd/mm/yyyy"  format... Can anyone suggest how to do this using Thanks aviThanks and  <body>    <form id="form1" runat="server">    <div>    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>    </div>            </form></body...

Problem in Date Comparison with Compare Validator in "dd/MM/yyyy" format
I want to compare dates  for that I have taken two textboxes in which dates are coming through ajax calendar in "dd/MM/yyyy" format I am using compare validator  for comparing with condition that value in textbox2 should be greater than textbox 1  in textbox1 if I enter date suppose"10/03/2008"  and in textbox 2  "11/03/2008" it works fine But in textbox1 if I enter "20/02/2008" and in textbox 2 "11/03/2008" it doesn't works and give message "value in textbox2 should be greater than textbox 1&quo...

Request.Form["Label1.Text"]; and ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
Hi I am using request.form[]; to retrive Default.aspx  data in Welcome.aspx page, It works better.But when I am trying to retrive the same data of Welcome.aspx page in the ChangePassword.aspx  page using request.from[]; I am getting blank output, Here is the snippet using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OleDb;...

wrong character display ("�" displays as "�" or "?")
Using ODBC Sybase 11 router, the character "�", saved in a varchar column in Sybase 11.5 will display as "�" or "?" in SQL Advantage or in our application. This just started occuring once we changed our applications to use 32 bit ODBC connection, rather than DBLib 16 bit. What is really interesting is that our our old 16 bit application runnning on the same PC returns the characters correctly, while 32 bit application running against ODBC returns another character, usually the degree symbol. Both versions of this program are accessing the same data sou...

Web resources about - How to display "dd-mm-yyyy" format from database to text box ? -

Resources last updated: 12/1/2015 4:53:53 PM