locked
Want to select the record by Date from Datatable in VB.net

    Question

  • Hi all,

    I have a dataset, which have a column create_date which have value(5/12/2011 12.54.00) , but i want to select the value from dataset with date only not by time (i.e. 5/12/2011),

    Current code:
    oDatatable.Select("create_date = " & cDate(Now.date))
    But it will only selecting row if the data and time both are same, but i want to select if the data is same.

    Please give a solution for this,


    Thanks,
    Dhiraj

    Saturday, May 14, 2011 5:01 AM

Answers

  • Dhiraj,

    Try changine the Select expression from "create_date = " & CDate(Now.Date) to the following:

    System.String.Format("create_date >= #{0}# And create_date < #{1}#", System.DateTime.Today.ToString("d"), System.DateTime.Today.AddDays(1).ToString("d"))

    resulting in:

     oDatatable.Select(System.String.Format("create_date >= #{0}# And create_date < #{1}#", System.DateTime.Today.ToString("d"), System.DateTime.Today.AddDays(1).ToString("d")))


    Thanks, Jayson
    • Proposed as answer by Jayson Furr Saturday, May 14, 2011 5:13 AM
    • Marked as answer by Dhiraj3301 Saturday, May 14, 2011 12:51 PM
    Saturday, May 14, 2011 5:13 AM

All replies

  • Dhiraj,

    Try changine the Select expression from "create_date = " & CDate(Now.Date) to the following:

    System.String.Format("create_date >= #{0}# And create_date < #{1}#", System.DateTime.Today.ToString("d"), System.DateTime.Today.AddDays(1).ToString("d"))

    resulting in:

     oDatatable.Select(System.String.Format("create_date >= #{0}# And create_date < #{1}#", System.DateTime.Today.ToString("d"), System.DateTime.Today.AddDays(1).ToString("d")))


    Thanks, Jayson
    • Proposed as answer by Jayson Furr Saturday, May 14, 2011 5:13 AM
    • Marked as answer by Dhiraj3301 Saturday, May 14, 2011 12:51 PM
    Saturday, May 14, 2011 5:13 AM
  • try this piece of sql statement is your select:

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


    Mitja
    Saturday, May 14, 2011 6:22 AM
  • Jayson,

    My issue is fixed by solution given by you,

    Thanks, Dhiraj

    Saturday, May 14, 2011 12:53 PM