Working with datetime variables

Stimulsoft Reports.NET discussion
Post Reply
tynar
Posts: 25
Joined: Thu Mar 17, 2011 11:54 pm
Location: Kyrgyzstan

Working with datetime variables

Post by tynar »

Hello,

In datasets I would like to assign a date start of year to variable.

I wrote following SQL:

DECLARE @startOfYear datetime

select @startOfYear = cast(cast(YEAR(@EndDatePar) AS VARCHAR(4)) + '0101' AS datetime) --DATEADD(YEAR ,DATEDIFF(YEAR ,0 ,@EndDatePar) ,0)

but I receive error:
"Conversion failed when converting date and/or time from character string." on clicking Receive Columns.

@EndDatePar is a parameter associated with a variable which user enters and I'm working in Designer.

Would much appreciate your help.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Working with datetime variables

Post by HighAley »

Hello.
tynar wrote:In datasets I would like to assign a date start of year to variable.

I wrote following SQL:

DECLARE @startOfYear datetime

select @startOfYear = cast(cast(YEAR(@EndDatePar) AS VARCHAR(4)) + '0101' AS datetime) --DATEADD(YEAR ,DATEDIFF(YEAR ,0 ,@EndDatePar) ,0)

but I receive error:
"Conversion failed when converting date and/or time from character string." on clicking Receive Columns.

@EndDatePar is a parameter associated with a variable which user enters and I'm working in Designer.

Would much appreciate your help.
Please, try to use next expression:

Code: Select all

select @startOfYear = cast((cast(YEAR(@EndDatePar) AS VARCHAR(4)) + '0101') AS datetime) --DATEADD(YEAR ,DATEDIFF(YEAR ,0 ,@EndDatePar) ,0)
Otherwise, please send us your report template with data for analysis.

Thank you.
tynar
Posts: 25
Joined: Thu Mar 17, 2011 11:54 pm
Location: Kyrgyzstan

Working with datetime variables

Post by tynar »

I tried your suggestion without success.

Please find in attachments example report file.
Attachments
1477.dateTime_test.mrt
(3.85 KiB) Downloaded 331 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Working with datetime variables

Post by HighAley »

Hello.

Please, try to use next query:

Code: Select all

declare @startOfYear datetime

select cast(cast(YEAR(@nowDatePar) AS VARCHAR(4)) + '0101' AS datetime) col1
Thank you.
Post Reply