Author |
Topic  |
|
phrankbooth
Posting Yak Master
USA
162 Posts |
Posted - 05/20/2013 : 14:34:15
|
This: SELECT SUBSTRING(convert(varchar, getdate(), 126),0,10)
Gives me: 2013-05-2
But I need: 2013-05-02
I had thought the DD would have automatically done that.
--PhB |
|
MIK_2008
Flowing Fount of Yak Knowledge
Pakistan
1054 Posts |
Posted - 05/20/2013 : 14:46:01
|
Are you looking for only date portion???
SELECT Convert(date,getdate())
P.S. I would suggest to handle formatting on the front end of the application (if you need it in any application). Else stick with the standard date type with in SQL.
Cheers MIK |
 |
|
phrankbooth
Posting Yak Master
USA
162 Posts |
Posted - 05/20/2013 : 14:53:31
|
thanks for the quick reply!
There's no front end. These are internal calls.
--PhB |
 |
|
jimf
Flowing Fount of Yak Knowledge
USA
2875 Posts |
Posted - 05/20/2013 : 14:59:26
|
Start your substring at 1, not 0, and always declare the lengths of your varchars! SELECT SUBSTRING(convert(varchar(10), getdate(), 126),1,10)
Jim
Everyday I learn something that somebody else already knew |
 |
|
Lamprey
Flowing Fount of Yak Knowledge
4614 Posts |
Posted - 05/20/2013 : 15:49:44
|
SELECT FORMAT(SYSDATETIME(), 'yyyy-MM-dd', 'en-us') |
 |
|
bandi
Flowing Fount of Yak Knowledge
India
2242 Posts |
Posted - 05/21/2013 : 00:49:59
|
--see this format.....( 2013-05-02) DECLARE @date DATE = getdate()-19 SELECT CONVERT(VARCHAR(10), @date, 120) AS [YYYY-MM-DD] SELECT REPLACE(CONVERT(VARCHAR(10), @date, 111), '/', '-') AS [YYYY-MM-DD]
-- Chandu |
 |
|
madhivanan
Premature Yak Congratulator
India
22864 Posts |
Posted - 05/22/2013 : 06:32:27
|
The FORMAT function is available from verrsion 2012 onwards. However if you use front end application to show this format, use format function there
Madhivanan
Failing to plan is Planning to fail |
 |
|
|
Topic  |
|