Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
phrankbooth
Posting Yak Master
162 Posts |
Posted - 2013-05-20 : 14:34:15
|
This:SELECT SUBSTRING(convert(varchar, getdate(), 126),0,10)Gives me:2013-05-2But I need:2013-05-02I had thought the DD would have automatically done that.--PhB |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-05-20 : 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.CheersMIK |
|
|
phrankbooth
Posting Yak Master
162 Posts |
Posted - 2013-05-20 : 14:53:31
|
thanks for the quick reply!There's no front end. These are internal calls.--PhB |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2013-05-20 : 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)JimEveryday I learn something that somebody else already knew |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-05-20 : 15:49:44
|
[code]SELECT FORMAT(SYSDATETIME(), 'yyyy-MM-dd', 'en-us')[/code] |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-05-21 : 00:49:59
|
--see this format.....( 2013-05-02)DECLARE @date DATE = getdate()-19SELECT 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
22864 Posts |
Posted - 2013-05-22 : 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 thereMadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|