Format date paramer

Stimulsoft Reports.PHP discussion
Post Reply
tony.tomov
Posts: 72
Joined: Mon Jun 07, 2010 2:39 am

Format date paramer

Post by tony.tomov »

Hello,


Could not find somthing about this.

When define a Variable to be set as parameter and set it as datetime the formating can not be changed, which causes wrong search in database.
Will be possible to change the date formating on user interaction or reformat it in where clause in sql query - e.g like 2018-03-08 instead of 03/08/2018
Thank you.

P.S The posted value in SQL contain always datetime value instead that the format is set to date only. How can only build separately date, datetime or time
Attachments
Screenshot from 2018-03-08 22-20-34.png
Screenshot from 2018-03-08 22-20-34.png (3.42 KiB) Viewed 9616 times
Screenshot from 2018-03-08 22-18-13.png
Screenshot from 2018-03-08 22-18-13.png (24.71 KiB) Viewed 9616 times
tony.tomov
Posts: 72
Joined: Mon Jun 07, 2010 2:39 am

Re: Format date paramer

Post by tony.tomov »

Hello again.

Setting the variable field to string solves the problem, but we lost the datepicker which is important.

The other question is - how can we attach a date-picker to string search field and this datepicker to be configured to return a date in certain (custom) format

I use the latest version 2018.1.8

Thank you.

Kind Regards,
Tony
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Format date paramer

Post by Alex K. »

Hello,

Unfortunately, it is not possible to set the custom format for DateTime variable, it depends on system culture settings.
You can use the convert function in the query.

Thank you.
tony.tomov
Posts: 72
Joined: Mon Jun 07, 2010 2:39 am

Re: Format date paramer

Post by tony.tomov »

Alex K. wrote:

You can use the convert function in the query.

Thank you for the response. Any advice haw to implement this? The problem I see is: How to detect the datetime format of the culture, since different browsers have different language setting.
With simple words - how to get the datetime formatting of the culture in the query?
Appreciate any help on this.

Kind Regards
Tony
tony.tomov
Posts: 72
Joined: Mon Jun 07, 2010 2:39 am

Re: Format date paramer

Post by tony.tomov »

Setting the culture changes the display of the date in the report, but does not change the date format of the parameter for use with datepicker

I have do this into the viewer. php and designer php

Code: Select all

	<?php 
		$options = StiHelper::createOptions();
		$options->handler = "handler.php";
		$options->timeout = 30;
		StiHelper::initialize($options);
	?>
	<script type="text/javascript">
		Stimulsoft.System.Globalization.CultureInfo.currentCulture = Stimulsoft.System.Globalization.CultureInfo.cultures["bg-BG"];
		Stimulsoft.Base.Localization.StiLocalization.setLocalizationFile("localization/bg.xml");
but the format of date parameter does not change - it is always dd/MM/yy H:i:s
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Format date paramer

Post by Alex K. »

Hello,

Please try to use the convert to necessary format directly in the query expression. Something like:
{DateTimeVar.ToString('yyyy-MM-dd')}

Thank you.
tony.tomov
Posts: 72
Joined: Mon Jun 07, 2010 2:39 am

Re: Format date paramer

Post by tony.tomov »

Hello,


Thanks. It is working.
The correct way to write it is with double brackets like this

Code: Select all

SELECT ... FROM ... WHERE .. AND OrderDate >=  '{Variable4.ToString("yyyy-MM-dd")}' ....
since the date in MySql is treated as string and we need to pass a string

Kind Regards,
Tony
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Format date paramer

Post by Alex K. »

Hello

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

Thank you.
Post Reply