Showing posts with label ugly. Show all posts
Showing posts with label ugly. Show all posts

Monday, March 19, 2012

Date in current Month?

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 */
>
>
>

Sunday, March 11, 2012

date formatting or localization

I have written this ugly expression because I didn't know any other way. What I am trying to do is convert an English date string to a French string.

example

January 2005 > Janvier 2005

Thank you,

Pavel

=Switch(

Month(CDate(Fields!Month.Value) ) = 1, "Janvier" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 2, "Fevrier" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 3, "Mars" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 4, "Avril" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 5, "Mai" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 6, "Juin" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 7, "Juillet" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 8, "Aout" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 9, "September" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 10, "Octobre" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 11, "November" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 12, "December" & " " & Year(CDate(Fields!Month.Value))

)The only thing I see wrong with this is that you have Year(CDate(Fields!Month.Value) and that will not produce a result, correct?|||The field Month.Value stores "January 2004". I get the value from Analysis Services.

Pavel