You must Sign In to post a response.
  • Category: ASP.NET

    How to change the textbox date to ddmmyyy format in c#

    i want to validate the textboxdate and gridview row date in c#

    My code as follows

    DateTime selectedfromdate = Convert.ToDateTime(Txtfromdate.SelectedDateValue);
    for (int i = 0; i < GvSch.Rows.Count; i++)
    if (selectedfromdate == Convert.ToDateTime(rows.Cells[0].Text.ToString().Trim()))
    Lblerr.Text = "selected date and excel sheet should be same";

    When i debug and check
    In selectedfrom date value is 9/2/2014 12:00:00 AM
    rows.cells[0].text.tostring(),trim() value is 1-Sep-14

    i want to change the format of selectedfrom date is 1-sep-14 format.

    like same as gridview date format 1-Sep-14.

    for that how can i do in using c#.
  • #750832
    Hello narasiman,
    This question is being repeated by you.

    But then also

    You just need to make a small change for this,

    In your code, change following

    DateTime selectedfromdate = Convert.ToDateTime(Txtfromdate.SelectedDateValue);


    DateTime selectedfromdate = Convert.ToDateTime(Txtfromdate.SelectedDateValue.ToString("d-MMM-yy"));

    in ToString() Func you can specify any format for ex:-

    ddMMMyyyy, ddMMyyyy, ddMMyyyy HH:mm:ss, and so on..

    Shakil Sama

  • #750879

    Use .ToString() method to convert your date field as you want.



    Hope this will help you..

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #750910
    Hi Narasiman, use ToString() method to convert selected date value to dd-MMM-yy

    ex selectedfromdate.ToString("dd-MMM-yy")

    then selectedfromdate format is 1-Sep-14

  • #751108

    To convert a textbox for date in some specific format, you can use the below code-

    DateTime theDate=DateTime.ParseExact(TextBox1.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
    string dateToInsert=theDate.ToString("ddMMyyyy");

    Hope this will help you !!

    Ashutosh Jha

  • #751129

    Please refer below code:
    System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;

    DateTime Todate = DateTime.ParseExact(txtDocumentDateTo.Text, "dd-MM-yyyy", provider);

    Hope this will help you.

    Ram Prasad

  • Sign In to post your comments