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.



    Thanks,
    Madhu
  • #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.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

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

    SELECT CONVERT(VARCHAR(10),GETDATE(),105)


    it will show following result :
    20-07-2011

    If it helps you then Rate this.

    Best Regards,
    Manoranjan Sahoo
    http://www.dotnetsquare.com

  • #621401
    Hi Madhu

    can you can the Date to textbox

    string dt=ds.Table[0].Row[0]["CreatedDate"].Tostring();
    txtDate.Text=Convert.ToDateTime(dt).ToString("dd/MM/yyyy");


    Or

    In select Query


    select convert(varchar, getdate(), 103)

    Regards
    N.Subhash

  • #621405
    Thank you all
    its working





    Thaks,
    Madhu.


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.