DATETIME with date and time

  • I want something like this:

    DECLARE @datetime DATETIME;

    SET @datetime = Getdate();

    Except in the form of:

    2014-01-28 18:35:25

    or something with the date and time.

  • To display it, you need to use CONVERT with format code 120.

    You should, however, store datetime values as datetype types which have no format predefined.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Is this how you would do it?

    DECLARE @datetime DATETIME;

    SET @datetime = Getdate();

    CONVERT (datetime , 120);

  • Have you tried it?

    It might not return the expected results because you're not including your variable in the function.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Sorry,

    Will this work:

    DECLARE @datetime DATETIME;

    SET @datetime = Getdate();

    CONVERT (@datetime , 120);

  • Now you're not including the target data type. Have you opened the link I provided?

    And you are missing the SELECT statement.

    Tip: If you select a function and press F1, you'll get immediately to the help article on that item.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 6 posts - 1 through 5 (of 5 total)

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