locked
Inputting date through insert command RRS feed

  • Question

  • How do type the date in the insert command when inputting data?
    Saturday, October 1, 2011 11:28 AM

Answers

  • The best way to specify date strings in SQL Server is with an ISO 8601 format.  This avoids ambiguity dependent on the session DATEFORMAT settings.  Unseparated and separated examples:

     

    SELECT CAST('20111001' AS date); --October 1, 2011
    SELECT CAST('2011-10-01T00:00:00' AS date); --October 1, 2011
    
    

    See Tibor's article for an extended discussion:  http://www.karaszi.com/SQLServer/info_datetime.asp

     

     

     


    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
    • Proposed as answer by Stephanie Lv Tuesday, October 4, 2011 11:50 AM
    • Marked as answer by Stephanie Lv Monday, October 10, 2011 1:25 PM
    Saturday, October 1, 2011 11:54 AM
    Answerer

All replies

  • How do type the date in the insert command when inputting data?
    • Merged by Stephanie Lv Monday, October 3, 2011 12:16 PM duplicated thread
    Saturday, October 1, 2011 11:27 AM
  • The best way to specify date strings in SQL Server is with an ISO 8601 format.  This avoids ambiguity dependent on the session DATEFORMAT settings.  Unseparated and separated examples:

     

    SELECT CAST('20111001' AS date); --October 1, 2011
    SELECT CAST('2011-10-01T00:00:00' AS date); --October 1, 2011
    
    

    See Tibor's article for an extended discussion:  http://www.karaszi.com/SQLServer/info_datetime.asp

     

     

     


    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
    • Proposed as answer by Stephanie Lv Tuesday, October 4, 2011 11:50 AM
    • Marked as answer by Stephanie Lv Monday, October 10, 2011 1:25 PM
    Saturday, October 1, 2011 11:54 AM
    Answerer
  • I replied to your other thread, which is a duplicate of this question.  Consider posting questions related to T-SQL to the more appropriate Transact-SQL forum (http://social.msdn.microsoft.com/Forums/en-US/transactsql).

     


    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
    Saturday, October 1, 2011 11:58 AM
    Answerer
  • Hi,
    Check this thread.
    http://www.4guysfromrolla.com/articles/081507-1.aspx#postadlink
    Shatrughna
    Saturday, October 1, 2011 12:17 PM