Professional Web Applications Themes

Dates and times - Microsoft SQL / MS SQL Server

I need two different table fields. One with dates, but in short format, like dd/mm/yyyy and the other in the time format, like hh:mm. I think the solution is creating a user type. But, how can i write the rule? Could anybody give some examples? Thanks in advance!...

  1. #1

    Default Dates and times

    I need two different table fields. One with dates, but in short format, like
    dd/mm/yyyy and the other in the time format, like hh:mm. I think the
    solution is creating a user type. But, how can i write the rule? Could
    anybody give some examples?
    Thanks in advance!


    Taryon Guest

  2. #2

    Default Re: Dates and times

    how about creating computed column.
    Ex:
    create table #t (dt datetime , only_dt as convert(varchar(25), dt, 111),
    only_time as convert(varchar(25), dt, 108))
    insert into #t (dt) values(getdate())
    select * from #t

    --
    -Vishal
    "Taryon" <com.br> wrote in message
    news:phx.gbl... 
    like 


    Vishal Guest

  3. #3

    Default Re: Dates and times

    You can use the CONVERT function to extract the date pieces. For example:
    SELECT CONVERT(VARCHAR(10), GetDate(), 101), CONVERT(VARCHAR(10), GetDate(),
    108)

    To split the field, you can create pseudo-fields in the table. For example:
    CREATE TABLE testTable
    (
    dateField DATETIME,
    dateSection AS CONVERT(VARCHAR(10), dateField, 101),
    timeSection AS CONVERT(VARCHAR(10), dateField, 108)
    )
    Now, when you insert a date into the table, the "dateSection" and the
    "timeSection" get automatically populated.
    --
    HTH,
    SriSamp
    Please reply to the whole group only!
    http://www32.brinkster.com/srisamp

    "Taryon" <com.br> wrote in message
    news:phx.gbl... 
    like 


    SriSamp Guest

  4. #4

    Default Re: Dates and times

    thank you guys!

    "Taryon" <com.br> escreveu na mensagem
    news:phx.gbl... 
    like 


    Taryon Guest

Similar Threads

  1. Dates & SQL
    By smokin_joe in forum Coldfusion Database Access
    Replies: 1
    Last Post: July 29th, 04:56 PM
  2. ASP/VBS Dates Between Dates
    By Sanjay in forum Dreamweaver AppDev
    Replies: 3
    Last Post: April 28th, 06:34 PM
  3. Default Dates & Times in Existing Records
    By boconnor in forum Microsoft Access
    Replies: 1
    Last Post: August 1st, 01:49 PM
  4. Help with Dates please
    By Ian Piper in forum Microsoft SQL / MS SQL Server
    Replies: 4
    Last Post: July 7th, 07:55 PM

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