Page 1 of 1

Using Variable in query of type Datetime

Posted: Fri Oct 06, 2017 9:42 am
by mayaa
Hi,

I have created a variable NovSt of type Datetime and assigned it a value from the calendar as 31 October 2017. similarly, have another variable as NovEnd with value 04 December, 2017.

I am using this variable in my datasource query as :
SELECT CASE WHEN EVENT_START_DATE BETWEEN '{NovSt}' AND '{NovEnd}' THEN 'NOVEMBER' END

Formed query:
SELECT CASE WHEN EVENT_START_DATE BETWEEN DATE('10/31/2017 00:00:00 AM') AND DATE('12/04/2017 11:59:59 PM') THEN 'NOVEMBER 2017')

EVENT_START_DATE format is : yyyy-mm-dd hh:mm:ss whereas the Variable value format is : 'mm/dd/yyyy hh:mm:ss'. I need Variables format same as EVENT_START_DATE format to check its value in the range.

How do I change its format?
Please note I tried DATE_FORMAT('{NovDate}', '%Y-%m-%d %T') but it returns NULL as I am using MySql

Re: Using Variable in query of type Datetime

Posted: Fri Oct 06, 2017 12:21 pm
by Alex K.
Hello,

Please try to use the ToString() method with the necessary format:
SELECT CASE WHEN EVENT_START_DATE BETWEEN '{NovSt.ToString("NecessaryDateTimeFormat")}' AND '{NovEnd.ToString("NecessaryDateTimeFormat")}' THEN 'NOVEMBER' END

Thank you.

Re: Using Variable in query of type Datetime

Posted: Fri Oct 06, 2017 7:35 pm
by mayaa
Hi Aleksey,

The solution worked perfectly! Thanks a lot for your quick response.

Regards,
Mayaa

Re: Using Variable in query of type Datetime

Posted: Sat Oct 07, 2017 11:49 am
by Alex K.
Hello

We are always glad to help you!
Please let us know if you need any additional help.

Thank you.

Re: Using Variable in query of type Datetime

Posted: Mon Oct 09, 2017 6:27 am
by mayaa
Yes I would need your help in another issue which relates to Text formatting. Shall I start new thread or continue here?

Thanks.

Re: Using Variable in query of type Datetime

Posted: Mon Oct 09, 2017 6:59 pm
by Alex K.
Hello,

Could you explain your issue in more details?

Thank you.