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

    How to pass the datetime value from asp.net to MS SQL server for query?

    The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    Dear All

    I have a asp.net page which will get data from SQL server. After some selection on the data (datetime value), we will use a selected datetime value to search the MS SQL server's tables for further query results.

    I encountered the problem is .... after the use selection of the datetime value, the datetime value is in "MM/DD/YYYY HH:MM:SS". However the MS SQL server is only allow datetime format in "DD/MM/YYYY HH:MM:SS". So, could any one help me how to make things work? How to reformat the datetime before I pass it back to the MS SQL server for query?

    Thanks a lot
    Bryan
  • #58094
    use this link for datetime convertion

    http://sqljunkies.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk

  • #58097
    hi......
    first make sure that after selecting date shlold be in the format MM/dd/yyyy HH:mm:ss am/pm
    then u can insert in the database.....

    Regards.......
    Seetaram.C

  • #58099
    than try to change the date formnat format by using the following code:
    Convert.ToDateTime(ddDateFrom.SelectedValue).ToString("MM/dd/yyyy");

  • #58100
    you can convert the date fromat in to SQL date formats by using

    DECALRE @DT DATETIME
    SET @DT='12-22-2006 10:18:34 pm'
    SELECT CONVERT(VARCHAR(50),@DT,103)


    http://www.aspfaq.com/show.asp?id=2460


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