I want to know if @.MyDate (DateTime) is in the current month. This works,
but it's ugly. Any ideas to make it look nicer?
if (datepart(year,current_timestamp) = datepart(year,@.MyDate) and
datepart(month,current_timestamp) = datepart(month,@.MyDate))
/* Yes*/
else
/* No */Is this any prettier?
If CONVERT(char(6),@.MyDate,112) = CONVERT(char(6),CURRENT_TIMESTAMP,112)
/* yes */
Else
/* no */
Gert-Jan
JM wrote:
> I want to know if @.MyDate (DateTime) is in the current month. This works,
> but it's ugly. Any ideas to make it look nicer?
> if (datepart(year,current_timestamp) = datepart(year,@.MyDate) and
> datepart(month,current_timestamp) = datepart(month,@.MyDate))
> /* Yes*/
> else
> /* No */|||Yes, your's is much better since it doesn't have two parts. It's always
helpful whenever I try something, then get a push from an expert. I learn a
lot that way.
Thanks!
"Gert-Jan Strik" <sorry@.toomuchspamalready.nl> wrote in message
news:421A38B5.98921D2E@.toomuchspamalready.nl...
> Is this any prettier?
> If CONVERT(char(6),@.MyDate,112) = CONVERT(char(6),CURRENT_TIMESTAMP,112)
> /* yes */
> Else
> /* no */
> Gert-Jan
>
> JM wrote:
works,|||Try this:
If @.MyDate >= dateadd(month,datediff(month, '20000101', getdate()), '
20000101' )
and @.MyDate < dateadd(month,1+datediff(month, '20000101', getdate()), '
20000101' )
...
Steve Kass
Drew University
JM wrote:
>I want to know if @.MyDate (DateTime) is in the current month. This works,
>but it's ugly. Any ideas to make it look nicer?
>if (datepart(year,current_timestamp) = datepart(year,@.MyDate) and
> datepart(month,current_timestamp) = datepart(month,@.MyDate))
> /* Yes*/
>else
> /* No */
>
>
>|||Try,
if datediff(month, @.MyDate, GETDATE()) = 0
print 'yes'
else
print 'no'
AMB
"JM" wrote:
> I want to know if @.MyDate (DateTime) is in the current month. This works,
> but it's ugly. Any ideas to make it look nicer?
> if (datepart(year,current_timestamp) = datepart(year,@.MyDate) and
> datepart(month,current_timestamp) = datepart(month,@.MyDate))
> /* Yes*/
> else
> /* No */
>
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment