how to insert the exact date in database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?U2FpbXZw?=

    how to insert the exact date in database

    Hello to all.
    Please help me.
    I'm inserting a date into sqlserver 2005 using C#3. my problem is while
    insert is successfull my date and time.
    It's possible to insert only a date?


    --
    To be Happy is To be Yourself
  • =?Utf-8?B?TW9ydGVuIFdlbm5ldmlrIFtDIyBNVlBd?=

    #2
    RE: how to insert the exact date in database

    Hi,

    SQLServer 2005 doesn't support only Date, so no, you can only insert a
    DateTime.Today to simulate only Date. This will change with SQLServer 2008,
    which supports Date, Time and DateTime and a few others as well.

    --
    Happy Coding!
    Morten Wennevik [C# MVP]


    "Saimvp" wrote:
    Hello to all.
    Please help me.
    I'm inserting a date into sqlserver 2005 using C#3. my problem is while
    insert is successfull my date and time.
    It's possible to insert only a date?
    >
    >
    --
    To be Happy is To be Yourself

    Comment

    • Roger Frost

      #3
      Re: how to insert the exact date in database

      "Morten Wennevik [C# MVP]" <MortenWennevik @hotmail.comwro te in message
      news:D234B629-D652-4FF3-83CE-1E3A636F2F7A@mi crosoft.com...
      Hi,
      >
      SQLServer 2005 doesn't support only Date, so no, you can only insert a
      DateTime.Today to simulate only Date. This will change with SQLServer
      2008,
      which supports Date, Time and DateTime and a few others as well.
      Coming soon: more types! I love it!!!!!!!!!

      --
      Roger Frost
      "Logic Is Syntax Independent"


      Comment

      • DMG

        #4
        Re: how to insert the exact date in database

        On Mar 18, 4:21 am, Morten Wennevik [C# MVP]
        <MortenWenne... @hotmail.comwro te:
        Hi,
        >
        SQLServer 2005 doesn't support only Date, so no, you can only insert a
        DateTime.Today to simulate only Date.  This will change with SQLServer 2008,
        which supports Date, Time and DateTime and a few others as well.
        >
        --
        Happy Coding!
        Morten Wennevik [C# MVP]
        >
        >
        >
        "Saimvp" wrote:
        Hello to all.
        Please help me.
        I'm inserting a date into sqlserver 2005 using C#3. my problem is while
        insert is successfull my date and time.
        It's possible to insert only a date?
        >
        --
        To be Happy is To be Yourself- Hide quoted text -
        >
        - Show quoted text -
        For what it is worth here are 2 UDF I have found that will set the
        time portion to 12:00:00a and make comparisons work better. The second
        one is more cryptic but supposedly faster.

        /dg

        -- #1
        Create function [dbo].[DateOnly](@DateTime DateTime)
        -- Returns @DateTime at midnight; i.e., it removes the time portion of
        a DateTime value.
        returns datetime
        as
        begin
        return dateadd(dd,0, datediff(dd,0,@ DateTime))
        end
        -- #2
        CREATE FUNCTION [dbo].[GetDateElement]( @inDateTime as DATETIME )
        RETURNS datetime AS
        BEGIN
        RETURN (select CAST(FLOOR( CAST(@inDateTim e AS FLOAT ) )AS
        DATETIME))
        END

        Comment

        • =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?=

          #5
          RE: how to insert the exact date in database

          The datetime type in SQL 2005 has both date and Time, but there is nothing to
          stop you from inserting only the date part of that and having all the times
          be the same (I think it ends up as midnight of that day).
          Alternately, you COULD make a varchar which stores the date as a string.
          That would kill date comparisons, but would allow you to store just the
          date...

          Ethan

          "Saimvp" wrote:
          Hello to all.
          Please help me.
          I'm inserting a date into sqlserver 2005 using C#3. my problem is while
          insert is successfull my date and time.
          It's possible to insert only a date?
          >
          >
          --
          To be Happy is To be Yourself

          Comment

          Working...