Professional Web Applications Themes

GetDate() - Microsoft SQL / MS SQL Server

When I employ the GetDate function, in inserts the date with a timestamp. Is there any way to have it simply input only the date? TIA...

  1. #1

    Default GetDate()

    When I employ the GetDate function, in inserts the date
    with a timestamp. Is there any way to have it simply
    input only the date? TIA
    Greg Guest

  2. #2

    Default Re: GetDate()

    Try:

    select convert (char (8), getdate ()), 112)

    --
    Tom

    ---------------------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
    SQL Server MVP
    Columnist, SQL Server Professional
    Toronto, ON Canada
    www.pinnaclepublishing.com/sql


    "Greg" <com> wrote in message news:0b6801c3576b$8abe4b70$gbl...
    When I employ the GetDate function, in inserts the date
    with a timestamp. Is there any way to have it simply
    input only the date? TIA

    Tom Guest

  3. #3

    Default Re: GetDate()

    First of all, it inserts the date with the time, not a timestamp.
    Secondly, it is a DateTime datatype, not a Date datatype.
    If you don't want the time, convert the values when selecting.
    Example: select convert(char(10), getdate(), 111)
    You could also force the time to '00:00:00' when inserting.

    "Greg" <com> wrote in message
    news:0b6801c3576b$8abe4b70$gbl... 


    raydan Guest

  4. #4

    Default Re: GetDate()

    Try,

    select Convert(smalldatetime,convert(varchar,getdate(),10 1))

    Praveen

    "Greg" <com> wrote in message
    news:0b6801c3576b$8abe4b70$gbl... 


    praveen Guest

  5. #5

    Default Re: GetDate()

    Greg,

    Datetime , as the name indicates, needs the time part to be inserted to the
    column and thats by design.However, while retrieving the date you can pass
    the third parameter with CONVERT to get only the date part.Try this:

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

    You can change the third parameter(112) in order to display date in a
    diff.format.These formats are discussed in the BooksOnLine topic 'Cast and
    convert.

    --
    Dinesh.
    SQL Server FAQ at
    http://www.tkdinesh.com

    "Greg" <com> wrote in message
    news:0b6801c3576b$8abe4b70$gbl... 


    Dinesh.T.K Guest

  6. #6

    Default GetDate()

     

    Check out 'Cast and Convert' in BOL. You can display the
    date in a number of different ways. For example:
    SELECT CONVERT(varchar(10), getdate(), 101)
    Jeff Guest

Similar Threads

  1. #25787 [Opn->Bgs]: 'yday' in getdate() function is out by one day
    By sniper@php.net in forum PHP Development
    Replies: 2
    Last Post: October 8th, 10:40 AM
  2. #25787 [NEW]: 'yday' in getdate() function is out by one day
    By australia at bookrealm dot com in forum PHP Development
    Replies: 0
    Last Post: October 8th, 08:24 AM
  3. getDate() vs {fn Now()}
    By Anith in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: July 14th, 07:59 PM
  4. remove time from getdate()
    By Vishal Parkar in forum Microsoft SQL / MS SQL Server
    Replies: 7
    Last Post: July 8th, 07:57 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139