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

    How to convert into date formate

    how to convert into date formate will search between two date.
  • #653585
    Date format is system dependent and the format settings can be changed using Control Panel. In your case you can derive differnt parts of the date e.g. year, month, day etc. from the string and create a new date out of it.

    Please check the following code:


    DateTime dt =new DateTime();
    string StrDt = "10/17/2011 7:29:04 PM";
    int day = Convert.ToInt32(StrDt.Substring(3,2));
    int month = Convert.ToInt32(StrDt.Substring(0,2));
    int year = Convert.ToInt32(StrDt.Substring(6,4));
    DateTime time= Convert.ToDateTime(StrDt.Substring(10));

    DateTime NewDt = new DateTime(year, month, day, time.Hour, time.Minute, time.Second);
    Response.Write(NewDt.ToString("dd/MM/yyyy hh:mm:ss tt"));


    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #653590
    DateTime dt= new DateTime();

    dt = Convert.ToDateTime("Your date time string value");

    Happy Coding.....
    Naveen V S

  • #653611
    try this code
    Convert.ToDateTime("Date Values in String");

    hope this will help you

  • #653640
    jignesh thanks for helping ..but its not working

  • #653729
    shahnawaz

    try like this


    //Convert your date using conversino method like below
    frmdate=Convert.ToDateTime(txtFrom.Text).ToString("yyyy-MM-dd")
    Todate=Convert.ToDateTime(txtTo.Text).ToString("yyyy-MM-dd")

    query="select * from emp where joindate between '" + frmdate + "' and '" + Todate + "'"

    Regards
    N.Ravindran
    Your Hard work never fails


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.