Professional Web Applications Themes

easy question. - Microsoft SQL / MS SQL Server

how do I do that? Convert 2003-07-14 13:54:58.000 TO 07/14/03 1:54PM...

  1. #1

    Default easy question.

    how do I do that?

    Convert
    2003-07-14 13:54:58.000

    TO
    07/14/03 1:54PM




    Mike Guest

  2. #2

    Default Re: easy question.

    the returned data type should be datetime also.

    "Mike" <com> wrote in message
    news:uaCv6T%phx.gbl... 


    Mike Guest

  3. #3

    Default Re: easy question.

    I don't know if it has that exact format but you should look at CONVERT() in
    BooksOnLine for the different ways you can convert a datetime to a string
    for displaying purposes. A Datetime is not stored as you see it displayed,
    it is stored as 2 integers. So if you want it to be displayed in a certain
    format you either have to use the gui tool in your front end to format it
    like you want or convert it to a string using CONVERT().

    --

    Andrew J. Kelly
    SQL Server MVP


    "Mike" <com> wrote in message
    news:uaCv6T%phx.gbl... 


    Andrew Guest

  4. #4

    Default Re: easy question.

    > the returned data type should be datetime also.

    Then you don't know what a datetime is. This is described very well in BOL
    (see Using Date and Time Data) but the short version is: datetimes do not
    contain formats. A datetime in SQL Server consists of a pair of integers:
    the first integer contains the number of days since the seed date; the
    second contains the number of milliseconds since midnight. No format. The
    client application, whether it is QA, or EM, or whatever, applies the
    formattion when the data is displayed.

    Only strings can be formatted, so you will need to return a varchar result.
    Look up the CONVERT function in BOL. Scroll down to the list of Style
    arguments for dates. None of them exactly match your requirement: the
    closest would be the first. If you can't live without mm/dd/yy h:mPM, you
    will need to do some concatenation. You can use the 1 argument to get the
    date part: CONVERT(char(10),datetime,1)

    For the time portion, you will need to use CONVERT and some string functions
    (are you sure you don't want to do this in your client code?):

    DECLARE datetime datetime
    SET datetime = '2003-07-14 13:54:58.000'
    SELECT
    CONVERT(char(9),datetime,1) +
    LTRIM(RIGHT(CONVERT(varchar(25),datetime,0),7))

    HTH,
    Bob Barrows

    Mike wrote: [/ref]


    Bob Guest

  5. #5

    Default Re: easy question.

    Use this one

    select CONVERT(VARCHAR,column_name,103)
    from TABLE NAME

    FAHEEM lATIF
    NETWOEK SOLUTIONS PAKISTAN.
     
    look at CONVERT() in 
    datetime to a string 
    see it displayed, 
    displayed in a certain 
    end to format it 
    >
    >
    >.
    >[/ref]
    Faheem Guest

  6. #6

    Default Re: easy question.

    the orginal problem is that if I do MAX(datetime) , then
    sometimes it would not work with datetime is string.

    "Faheem" <com> wrote in message
    news:071401c34c49$3bd08230$gbl... 
    > look at CONVERT() in 
    > datetime to a string 
    > see it displayed, 
    > displayed in a certain 
    > end to format it 
    > >
    > >
    > >.
    > >[/ref][/ref]


    Mike Guest

Similar Threads

  1. Easy Question
    By Chris Morris in forum PHP Development
    Replies: 20
    Last Post: March 4th, 03:06 PM
  2. Easy PHP question
    By Robert in forum PHP Development
    Replies: 3
    Last Post: December 28th, 06:20 AM
  3. very easy question here, plz help me!!!
    By deb_23 in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: February 13th, 03:23 AM
  4. Easy question = easy answer?
    By Jyry webforumsuser@macromedia.com in forum Macromedia Freehand
    Replies: 4
    Last Post: September 29th, 03:29 PM
  5. Easy Question/Easy Answer
    By ChuckyJ webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 1
    Last Post: July 12th, 01:50 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