RSS Feed

How to change the format of DateTime variable in ASP.NET

December 8, 2011 by Sourabh Sharma

This article will help you to change the display format of a DateTime variable in C#.NET. As you all know that DateTime variable is used to store date and time of any particular. and some time we need to change the format of this value. For Example some time we need to display only Date or only Time from the DateTime value. Also some time we need to change the format like DD:MM:YY or MM:DD:YY or anyone else. In this project we are using a calender control and we will learn how to change the format according to our requirement.

 


Free Download:
Date Format : Demo Project

 


Code of Web Page


protected void btngetdate_Click(object sender, EventArgs e)
    {
        DateTime dt = Calendar1.SelectedDate;
        string str = dt.ToString("dd:MM:yyyy");
        txtDate.Text = str;
    }




No Comments »

No comments yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>