Getdate function

  • When i use get date function it also give me the time how do i get only the ddmmyy part of the date here is my code

    update tbl1

    set insert_date = convert (varchar, getdate(), 106)

    where insert_date = null

    I though this might work but it won't update my table

    thanks

     

     

  • where insert_date is null

  • Additional information about NULL:

    http://qa.sqlservercentral.com/columnists/mcoles/fourrulesfornulls.asp

    No value can equal (=) null, Null is "Not Defined" or "Unknown"

    IS NULL is the proper way to determine if a value is null.

     

  • If you want get just the date from GetDate() without the time, use CONVERT and the 112 format.

    eg:

    -- Get current date (without time) as string:

    SELECT CONVERT( CHAR(8), GetDate(), 112)

    -- Get current date (without time) as date:

    SELECT CAST( CONVERT( CHAR(8), GetDate(), 112) AS DATETIME)

     


    Julian Kuiters
    juliankuiters.id.au

  • Francis, when using the CONVERT function, I suggest you always specify an appropriate length for varchar, i.e.  SELECT CONVERT (varchar(11), getdate(), 106). Using varchar by itself is just shorthand for varchar(30). The advantage to using date format 112 as Julian suggested is that it will insert properly with all regional date settings (it will always work).

  • Thanks for your help the where insert date = null was a mistake.. in the code..

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

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