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 |
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2011-08-18 : 06:36:54
|
| i have a date column,how can i know if i am in the currert half of year?suppose i have18-02-2011 'not current half of year'20-07-2011 'curren half of year' |
|
|
yadhu_cse
Constraint Violating Yak Guru
252 Posts |
Posted - 2011-08-18 : 06:45:55
|
| try thisselect datepart(month,getdate()) -- integer (1,2,3...) ,datepart(year,getdate()) -- integer ,datename(month,getdate())divide by 2 |
 |
|
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2011-08-18 : 06:51:34
|
| what is give to me?hust the current month??? |
 |
|
|
baburk
Posting Yak Master
108 Posts |
Posted - 2011-08-18 : 07:30:25
|
quote: Originally posted by inbs i have a date column,how can i know if i am in the currert half of year?suppose i have18-02-2011 'not current half of year'20-07-2011 'curren half of year'
DECLARE @MyDate VARCHAR(15)SET @MyDate = '2000-02-28'SELECT CASE WHEN (datepart(dayofyear, convert(varchar, @MyDate, 112)) = case month(dateadd(yy, YEAR(@MyDate) -1900,0)+59) when 2 then 366/ 2 else 365/ 2 end) Then 'True' ELSE 'False' END AS IsIamInMiddleOfYear--adding 59 days to it and then using the case statement to check whether the month is 2 or 3 depending on which leap year can be found out |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-18 : 09:30:35
|
| SELECT CASE WHEN DATEPART(yy,Datecol) = DATEPART(yy,GETDATE()) AND DATEPART(mm,Datecol)/6 = DATEPART(mm,GETDATE())/6 THEN 'In Current Half Year' ELSE 'Not in Current Half Year' END FROM Table------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|