Click here to Skip to main content
15,886,199 members

Display date as DD/MM/YYYY format.

Software Engineer 892 asked:

Open original thread
Dear Friends,

Good Day to every one of you............

I have a registration page to create the users..In this it has Issue date and Expiry date of user accessing the application.

I have set, Issue date will be the system date and for Expiry date administrator will choose it for the user.

For Expiry date I have a textbox with Ajax Calendar Extender....when i click on submit the expiry date is storing in database as 11/30/2012

But my requirement is.....

I want to display date as dd/MM/yyyy Format using label...I have used LABEL.

This is my code....Please help.

C#
protected void Page_Load(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(_connString);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "select datediff(dd,getdate(),ExpiryDate) as Edays, CONVERT(varchar, expirydate, 101) as ExpiryDates from dbo.UserAccounts where UserName='" + Session["UserName"].ToString() + "'";


        using (con)
        {
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {

            


               // lblExpiryDisplay.Text = DateTime.Parse(reader["ExpiryDates"].ToString()).ToString("dd/MM/yyyy");

                lblExpiryDisplay.Text = "Your Password will Expire on " + reader["ExpiryDates"].ToString() + " , and the Left Over days are " + reader["Edays"].ToString();


            }

           
        }
        con.Close();
        }
Tags: C#, ASP.NET, SQL Server

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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