date format

  • can i store 4/21/2003 3:32:53 PM and 4/21/2003 15:32:53,both the datetime types in a single table,if possible are they going to be equal?

  • No, in fact I don't think you will be able to insert them, unless you convert them into a single format. You are allow to store only one date format per column.

    When you query the table, you can give the date the format that you want.

    Another thing you can do is to create a separate column for the time, and save the time in that column, but with only one format again.

  • SQL Internal Datetime:

    datetime

    Date and time data from January 1, 1753 through December 31, 9999, to an accuracy of one three-hundredth of a second (equivalent to 3.33 milliseconds or 0.00333 seconds). Values are rounded to increments of .000, .003, or .007 seconds, as shown in the table.

    Example:

    Create Table Test(ColA datetime,COlB datetime)

    GO

    Set DateFormat mdy

    GO

    Insert Test values('4/21/2003 3:32:53PM','4/21/2003 15:32:53')

    GO

    Select * from Test Where COlA=ColB

    GO

    Drop Table Test

    GO

  • Date time as expressed by BOL

    quote:


    Values with the datetime data type are stored internally by Microsoft SQL Server as two 4-byte integers. The first 4 bytes store the number of days before or after the base date, January 1, 1900. The base date is the system reference date. Values for datetime earlier than January 1, 1753, are not permitted. The other 4 bytes store the time of day represented as the number of milliseconds after midnight.


    in otherwords it is stored as a number not as text or a specific format.

    You can enter most commonly accepted formats and can control the format based on SET DATEFORMAT. As for the look of the data being retrieved it can be express in many prefined formats using CONVERT (see BOL) or by using datepart funtionality to parse into your own customer format.

    As for your question of the 2 values you gave, the answers is yes they will be equal. 5409045121009 demonstrates this with his code example.

  • Thnks to all of you.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply