how to insert a date into a column

  • I will like to insert a date and time into a table

    When getdate()  is the value supplied the results have 1/1000th of second precision .Is there a way to truncate that?

    When inserted on a sized  char field the result is like Dec 22 2004  5:53AM

    The secons this time are missing

     

    Mike 

  • If you are inserting a date into a table, why are you not using a datetime field to store it?

    If you want to select just the date part of getdate(), the following will do it for you:

    select cast(floor(cast(getdate() as float)) as datetime)

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • A SmallDateTime field is accurate to the minute so setting it to GETDATE() will automatically truncate it for you.

  • If you want a specific format you could alway use something like

    SELECT LEFT(CONVERT(varchar, GETDATE(), 113),17)

    23 Dec 2004 10:04

    Best regards,

    Andrew

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

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