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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Get month from date field with two bytes

Author  Topic 

dan_coder
Starting Member

20 Posts

Posted - 2006-07-21 : 08:34:10
Hi guys

This is my problem: I have a table with a date field. I have to get month of this field using Month function, but result from jannuary to september is only one bytes long (1,2,3...10). How to extract two bytes (01,02,03...09)?

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-21 : 08:38:38
select right('00' + convert(varchar(2),month(dte)),2)
or
select right(convert(varchar(6),dte,112),2)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-07-21 : 08:41:44
Check the "Convert", "Datepart" & "Replicate" in Books On Line



Srinika
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-21 : 09:12:31
Or
select right(month(dte) + 100, 2)



KH

Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-07-21 : 09:26:04
Or

Why are you worrying about how many BITS it is? Sounds like a presentation problem, and should be handled on the FRONT END.

Help us help YOU!
Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)
Go to Top of Page
   

- Advertisement -