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

    How to remove time from date getting data from data base and assign text box

    How to remove time from date
    getting data from data base and assign text box.

    I want assign date to my text box but failed fill without time
    how can i filter time
    from my date field in date field in database
    using data set.

  • #621387
    You can use Split function with separator as ' ' space.

    String[] result = date.ToString().Split(' ');

    Textbox1.Text = result[0].ToString();

    Thanks and Regards,
    Himanshu Bhensdadia
    Microsoft Certified Professional(MCTS)

  • #621390
    convert first date-time to date
    then assign to text box
    or you can fetch data from database like this

    select convert(varchar(10) , dt_field_name ,103)
    from table_name

    ~~~~~~~~~~ Simply Making Effort ~~~~~~~
    Thanks and Regard
    Mahesh Nagar

  • #621395
    Hi Madhu,

    There are 3 ways to remove the time which is getting from the database.

    1. While rereieving the date from the database, format the date in such a way so only the date part will come in the dataset and then you can assign it directly to the date textbox.

    2. The other way is that with out touching the database, you just split the date with time from the space character and get the first part.

    3. After getting the date with time as string, you can formt it at the fronend by converting it in to date and then convert it in to .toShortDate. it will get only the date without time.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #621398
    you can use below code to get only date part :


    it will show following result :

    If it helps you then Rate this.

    Best Regards,
    Manoranjan Sahoo

  • #621401
    Hi Madhu

    can you can the Date to textbox

    string dt=ds.Table[0].Row[0]["CreatedDate"].Tostring();


    In select Query

    select convert(varchar, getdate(), 103)


  • #621405
    Thank you all
    its working


  • 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.