How to display date and time in string from datetime

  • Hi,

    My requirement is,

    I want to capture exact date and time,

    I am trying using,

    Select Convert(varchar(10),GetDate(),112)

    output :- 20131203

    Above statement gives me continues string of date,

    but also want to capture time.

    Desired output,

    201312030517

    Time should also come,and also continuesly no space in between

  • avdhut.k (12/3/2013)


    Hi,

    My requirement is,

    I want to capture exact date and time,

    I am trying using,

    Select Convert(varchar(10),GetDate(),112)

    output :- 20131203

    Above statement gives me continues string of date,

    but also want to capture time.

    Desired output,

    201312030517

    Time should also come,and also continuesly no space in between

    Why don't you just hand over a datetime datatyped column to your client application and let it handle presentation as per client settings ?

    Books online documents the convert statement quite well: http://technet.microsoft.com/en-us/library/ms187928%28v=sql.105%29.aspx

    So, if you really insist

    Select convert(char(23), getdate(), 121) as [yyyy:MM:dd HH:mm:ss.fff]

    , replace(replace(replace(replace(convert(varchar(20), getdate(), 121),'-',''),' ',''), ':',''), '.','') as [yyyyMMddHHmmss]

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

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