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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date Format Style

Author  Topic 

edusqluser
Starting Member

15 Posts

Posted - 2010-07-11 : 19:42:01
Anyone have the data style format for mm/yy?

THX, EDUSQLUSER

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-11 : 19:56:19
Use style 103 with CONVERT and then chop off the first three characters via RIGHT or SUBSTRING functions.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

edusqluser
Starting Member

15 Posts

Posted - 2010-07-11 : 22:21:50
This is my sample:

DECLARE @datBegin AS DATETIME
DECLARE @datEnd AS DATETIME

SET @datBegin = '@@START_DATE@'
SET @datEnd = '@@END_DATE@'

REPLACE (CONVERT (VARCHAR(10), '@@END_DATE@',103 ), '/', ' ')

Any suggestions to produce the mm yy?

THX, EDUSQLUSER
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-11 : 22:56:30
[code]select right(convert(varchar(10), getdate(), 3), 5)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2010-07-12 : 04:05:52
select substring(convert(varchar(10), getdate(), 3),4, 6)

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

edusqluser
Starting Member

15 Posts

Posted - 2010-07-12 : 12:45:12
Thanks. But I need to replace the "/". How do you do a Replace and a Right together so that the result is mm yy and not mm/yy?

THX, EDUSQLUSER
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-07-12 : 12:47:28
That's not what your original post says.

select replace(substring(convert(varchar(10), getdate(), 3),4, 6), '/', '')

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-16 : 11:48:07
If it is for formatting purpose, do it there in your front end application
If it is for finding all data for those months and year, use


where
date_col>=dateadd(month,datediff(month,0,@datBegin),0) and
date_col<dateadd(month,datediff(month,0,@datEnd)+1,0)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -