Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

DATETIME with date and time Expand / Collapse
Author
Message
Posted Tuesday, January 28, 2014 4:36 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 26, 2014 2:39 PM
Points: 23, Visits: 46
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.
Post #1535659
Posted Tuesday, January 28, 2014 5:17 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:44 PM
Points: 2,763, Visits: 5,901
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.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1535661
Posted Tuesday, January 28, 2014 5:49 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 26, 2014 2:39 PM
Points: 23, Visits: 46
Is this how you would do it?

DECLARE @datetime DATETIME;
SET @datetime = Getdate();
CONVERT (datetime , 120);
Post #1535671
Posted Tuesday, January 28, 2014 5:56 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:44 PM
Points: 2,763, Visits: 5,901
Have you tried it?
It might not return the expected results because you're not including your variable in the function.



Luis C.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1535675
Posted Tuesday, January 28, 2014 6:06 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 26, 2014 2:39 PM
Points: 23, Visits: 46
Sorry,

Will this work:

DECLARE @datetime DATETIME;
SET @datetime = Getdate();
CONVERT (@datetime , 120);
Post #1535679
Posted Tuesday, January 28, 2014 6:12 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:44 PM
Points: 2,763, Visits: 5,901
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.
I am a great believer in luck, and I find the harder I work the more I have of it. Stephen Leacock

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1535682
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse