Professional Web Applications Themes

Date/Time Format? - Microsoft SQL / MS SQL Server

No, not directly, you'd have to write your own proc / function. You could use this as a base: [url]http://www.aspfaq.com/2460[/url] So it might be something like this: CREATE FUNCTION dbo.formatWeirdDate ( dt DATETIME ) RETURNS VARCHAR(32) AS BEGIN DECLARE r VARCHAR(32), hr INT, hrVC VARCHAR(4) SET hr = DATEPART(HOUR, dt) SET hrVC = 'AM' IF hr > 12 BEGIN SET hr = hr - 12 SET hrVC = 'PM' END SET hrVC = CAST(hr AS VARCHAR(2)) + hrVC SET r = DATENAME(DW, dt) + ', ' + DATENAME(M, dt) + ' ' + CAST(DAY(dt) AS VARCHAR(2)) + ', ' + ...

  1. #1

    Default Re: Date/Time Format?

    No, not directly, you'd have to write your own proc / function. You could
    use this as a base:

    [url]http://www.aspfaq.com/2460[/url]


    So it might be something like this:


    CREATE FUNCTION dbo.formatWeirdDate
    (
    dt DATETIME
    )
    RETURNS VARCHAR(32)
    AS
    BEGIN
    DECLARE r VARCHAR(32), hr INT, hrVC VARCHAR(4)
    SET hr = DATEPART(HOUR, dt)
    SET hrVC = 'AM'
    IF hr > 12
    BEGIN
    SET hr = hr - 12
    SET hrVC = 'PM'
    END
    SET hrVC = CAST(hr AS VARCHAR(2)) + hrVC

    SET r = DATENAME(DW, dt) + ', ' + DATENAME(M, dt)
    + ' ' + CAST(DAY(dt) AS VARCHAR(2))
    + ', ' + CAST(YEAR(dt) AS CHAR(4))
    + ' (' + hrVC + ')'
    RETURN r
    END
    GO

    SELECT dbo.formatWeirdDate(GETDATE())
    GO

    DROP FUNCTION dbo.formatWeirdDate
    GO




    Assuming SQL Server 2000, of course. It's always nice to know what version
    you're using, so we're not chasing our tails for nothing...






    "Jason Davis" <jasondavis19hotmail.com> wrote in message
    news:#WGkFXzPDHA.1216TK2MSFTNGP11.phx.gbl...
    > Hi there,
    >
    > I have a datetime field which needs to be displayed as:
    >
    > "Monday, May 19, 2003 (10AM)"
    >
    > How can I achive that?
    >
    > Thanks
    >
    >

    Aaron Bertrand - MVP Guest

  2. #2

    Default Date/Time Format?

    Hi there,

    I have a datetime field which needs to be displayed as:

    "Monday, May 19, 2003 (10AM)"

    How can I achive that?

    Thanks


    Jason Davis Guest

Similar Threads

  1. date/time format
    By kt03 in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: September 17th, 01:51 AM
  2. Date/Time format with MS Access & CF
    By rapcgtiac in forum Macromedia ColdFusion
    Replies: 2
    Last Post: May 12th, 07:25 PM
  3. DW date & time format
    By samkry in forum Dreamweaver AppDev
    Replies: 0
    Last Post: May 12th, 10:25 AM
  4. Time/Date format and changing time to GMT
    By Shaiboy_UK in forum ASP
    Replies: 1
    Last Post: October 19th, 01:04 PM
  5. Nautulus: time/date format change ?
    By R@LF in forum Linux Setup, Configuration & Administration
    Replies: 3
    Last Post: August 9th, 07:16 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