I need to generate a year drop down with cake to populate ArchiveQuarter.year in the database. This is currently set in the database to 'year', but it was producing the same results with 'date'.
This is the current setup:
echo $this->Form->input('ArchiveQuarter.year', array(
'label'=>'Year',
'type'=>'date',
'dateFormat'=>'Y',
'minYear'=>'2000',
'maxYear'=>date('Y'),
));
The problem is that this produces a dropdown with a range of 1970-2013 instead of 2000-2013. The minYear does work though, because if you set it below 1970 then it will indeed work.
I literally copied and pasted your code into my CakePHP 2.3.0 app, and it worked as expected - gave me a select input from 2013 to 2000.
Maybe try getting the most recent version of CakePHP (your question doesn't list what version you're using) and try that?
Bottom line, the code you've provided does work - so if it's not for you, there are other factors in play.
I did some research into what was going on within the FormHelper.php file and here is a breakdown:
In the dateTime() function it checks if $attributes['value'] is empty. If it is it fills that information using $this->value($attributes,$fieldName); populating it with 2013
2013 is then parsed by _GetDateTimeValue()
Within _GetDateTimeValue() it is parsed as numeric, and is translated from unix time; an hour and a half into 1970.
That then is set as the value of the final select box, which has to expand from the minYear to properly accommodate.
For whatever reason Cake does not take into account the explicitely stated dateFormat=>'Y' when is parses with _GetDateTimeValue().
The solution is to insert: $selected => strtotime('now') which will in the end get properly parsed.
You can also explicitly set $selected to values outside of the range of dates, which I'm not sure would be a wanted before or not.
Related
Looking for help on this one. I'm working on a report in Report Builder that uses data from the Analysis Services cube and it is giving me a lot of problems when it come to any date/time data. I am trying to build a dynamic report that will allow the report to update depending on when it is viewed. I do this by setting parameters (#FromDateDate and #ToDateDate). Unfortunately MDX seems to hate dates which makes no sense to me.
My goal is to get data over a span of three months with the #ToDateDate being Today() and the #FromDateDate being 3 months in the past which I am able to achieve with this function (=DateAdd(DateInterval.Day,-90,Today()) ). However those don't go well with MDX.
My query looks like this:
SELECT
NON EMPTY
{[Measures].[Work Item Count]} ON COLUMNS
,NON EMPTY
{
[Date].[Year - Month - Date Hierarchy].[Date].ALLMEMBERS*
[Work Item].[System_State].[System_State].ALLMEMBERS*
[Work Item].[Microsoft_VSTS_Common_Severity].[Microsoft_VSTS_Common_Severity].ALLMEMBERS
}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM
(
SELECT
StrToMember
(#FromDateDate
,CONSTRAINED
)
:
StrToMember
(#ToDateDate
,CONSTRAINED
) ON COLUMNS
FROM
(
SELECT
{[Work Item].[System_WorkItemType].&[Bug]} ON COLUMNS
FROM
(
SELECT
{
[Team Project].[Team Project Hierarchy].&[{6F43CBFD-2E98-4CA7-B428-0B732603517A}]
} ON COLUMNS
FROM [Work Item]
)
)
)
WHERE
(
[Team Project].[Team Project Hierarchy].&[{6F43CBFD-2E98-4CA7-B428-0B732603517A}]
,[Work Item].[System_WorkItemType].&[Bug]
)
CELL PROPERTIES
VALUE
,BACK_COLOR
,FORE_COLOR
,FORMATTED_VALUE
,FORMAT_STRING
,FONT_NAME
,FONT_SIZE
,FONT_FLAGS;
I was able to figure out how to essentially inject he appropriate format by adjusting my Parameter Values in the Dataset Properties to this -
="[Date].[Date].&["+format(Parameters!FromDateDate.Value,"yyyy-MM-ddThh:mm:ss")+"]"
My two parameters have default values of :
=DateAdd(DateInterval.Day,-90,Today()) and =Today()
When I run my report I get the following error:
The restrictions imposed by the CONSTRAINED flag in the STRTOMEMBER function were violated.
Now if I remove CONSTRAINED from the STRTOMEMBER function I get another error. I have also tried removing the entire STRTOMEMBER function and just using the parameters which I can get to work in Management Studio but not in Report builder. Please Help! I have attempted so many different ways and still no success. Let me know what additional information is needed.
Another thing -
If I remove the T in the date format of the Parameter Value in the Dataset Property to look like this:
="[Date].[Year - Month - Date Hierarchy].[Date].&["+format(Parameters!FromDateYearMonthDateHierarchy.Value,"yyyy-MM-dd hh:mm:ss")+"]"
I get the below error:
The '2017-06-08 12:00:00' string cannot be converted to the date type.
So here is the solution if anyone is interested. I've seen a ton of forum posts online with no one having a concrete answer so I can see this is a common problem - the workaround at this link is valid and does work:
Using Dynamic MDX in Reporting Services
My issue was the format of my "injected" date. When running the query generated by my #ToDateDate and #FromDateDate parameters...
(note: after changes I made my parameters are now
#FromDateYearMonthDateHierarchy and '#ToDateYearMonthDateHierarcy`
which you will notice in my Parameter Value function)
My Parameter Values appeared in the following format:
[Date].[Year - Month - Date Hierarchy].[Date].&[2010-12-31T00:00:00]
In order to fix the issue for me my "injection statement" had to look like this:
"[Date].[Year - Month - Date Hierarchy].[Date].&[" & Format(CDate(Parameters!FromDateYearMonthDateHierarchy.Value),"yyyy-MM-dd") & "T00:00:00]"
With the actual date formatting of "yyyy-MM-dd") & "T00:00:00]" so in the end the hours minutes and second was what was giving me the headache. The injection works perfectly but just need to pay attention to the Formatting of the date and time. I genuinely hope this helps someone!
The question is based on SQL Server not about ssrs NEW Line
i had Already go through the stackoverflow below links related to this topic
1)New line in Sql Query
2)New line in sql server
3)New line in Sql Query
But i didn't get any answer for my situation
My problem is that i need a newline character in select query results
Example : i have a string like below
Today is Friday Yesterday is Thursday
and when I select this varchar value from my table I need it to to appear like this in my SSRS report:
Today is Friday
Yesterday is Thursday
I have tried many ways like
select 'Today is Friday' +char(13)+'Yesterday is Thursday'
but it gives me a result Today is Friday Yesterday is Thursday
but when i use print insted of select then i got the results what i want
But i cannot use print in my scenario because i need this result in aother query and that query i have used for ssrs reporting purpose
I know i can split this query and show it in two rows but in my case i can't do something like that too because the results i have used in many select querys.
i don't know it is possible in Sqlserver, if it is possible then
please help me to solve my problem
Edit : please help me if it is possible in Grid Mode rather than text mode
Since when you use print you do see the line break, it seems to me like the problem is that you execute this query in SSMS, while the result is displayed as a grid.
Try changing the display result to text and you will see the line break just like you see it when you use print instead of select.
Btw, I think you better use char(13)+char(10) as xQbert suggested in the comments.
If you are doing it in Managment Studio this works fine:
select 'Today is Friday' +char(13)+'Yesterday is Thursday'
If result to grid is selected in Managment Studio then it is printed in one line becouse this works in that way. If you copy and paste it from grid to notepad you will see it works. Try checking result to Text. It works to.
I have no experience with SSRS, but maybe this link is helpful for You:
SSRS how to add in New line
This suggest to use expression, like this:
=Replace(Field!Names.Value, ",", VbCrLf)
If you need to display the new line in an SSRS report, try using <br /> instead of CHAR(10) - and make sure to set the control that contains this text to allow HTML.
I have a report with a multi-valued parameter on it. I'm looking to output the selected values which is accomplished with Join(Parameters!State.Label,",")
Every solution I've found on the web indicates I should use something like the following to detect when the (Select All) "value" is selected.
E.g. expression for the text box on the header should be:
="State: " & IIF(countrows("prc_prompt_state").Equals(Parameters!State.Count),"(All)",join(Parameters!State.Label,","))
CountRows() tells me the total number of parameters available, e.g. 8 states in Australia. Parameters!State.Count is supposed to tell me how many are actually selected by the user. However this always reports the full value (8 in this case) regardless of how many are selected. This is in agreement with the official docs (https://technet.microsoft.com/en-us/library/aa337293(v=sql.100).aspx), but NOT in agreement with every single search result I come up with on how to solve this problem.
So how can I rewrite this expression so I can find out when (Select All) is/isn't checked? I'm using report builder 3, which I believe is based on the 2008 edition - we deploy to Azure, but I haven't got that far yet.
Examples of questions whose answers seem to be wrong:
Displaying Multi-Value Parameters
SSRS: Can I know if user selected "ALL" in multivalued param?
This is old, but google found it for me, and then I figured out an answer on my own that worked. (I was using a list of users.)
I created a separate dataset that returns a count of all available options in the default parameter lookup (username). Then, I assigned that as a default value to an internal parameter. (UserCount) This worked as a text expression:
=Microsoft.VisualBasic.Interaction.IIF(Parameters!username.Count = Parameters!UserCount.Value, "All Selected", Microsoft.VisualBasic.Strings.JOIN(Parameters!username.Value, ", "))
Hi Having a syntax issue - at least I think it is. I want a default date as part of a case statement inside a materialised view (MS SQL 2008 +):
, CASE
WHEN WithFirstDate = 0 THEN CONVERT(DATE,'1900-JAN-1', 101)
WHEN WithFirstDate = 1 THEN
Start1
ELSE --WithFirstDate = 2
Start2
END ValidDate
I'm getting the following error:
view uses an implicit conversion from string to datetime or smalldatetime. Use an explicit CONVERT with a deterministic style value
I'd like to have a solution that works irrespective of localization (i.e US style dates, Japanese style dates and the rest of the world)
Thanks
Instead of:
CONVERT(DATE,'1900-JAN-1', 101)
Just do:
CONVERT(DATE,'1900-01-01')
However the issue may be with the other two columns, Start1 and Start2. I am guessing these are not DATE columns.
The 101 code you are passing the CONVERT function does not match your format. Check the following link to find the correct code:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
Ok well this forum has gone downhill IMHO, first my post get endless edited for grammar which doesn't change the meaning, then it gets voted down presumably because it was "to difficult" to answer. https://stackoverflow.com/users/61305/aaron-bertrand was on the right lines. Thanks Aaron. The problem was a computed column in one of the referenced tables was non deterministic. This error only resolved in a flag when the materialising clustered index was being created on the view. I'd post a link to the full answer but not allowed. Shame I cant recover all my old badges and points from a couple of years ago. Full answer here http://tinyurl.com/knor8qk
I'm working on a report in Reporting Services and I can't figure out why I'm having trouble with Non-queried report parameters.
I'm trying to get the current year and have tried:
=YEAR(TODAY())
=DATEPART("yyyy",TODAY())
I have also tried TODAY instead of TODAY()
All of these seem to break the Year dropdown on my report. I thought if something was wrong it would just not get the correct default... but nope, it breaks the whole field.
Any thoughts? articles?
UPDATE:
Wait, wait, wait... the weirdest thing. The Year parameter is the second parameter of this report. And its grayed out (with no value) UNTIL I select the first parameter (im my case "category"). Am I somehow telling the Year param to do this? or does SSRS 2005 process the params in order? I don't think I ever noticed this before.
UPDATE 2:
Please see all comments
=DateTime.Today.Year
should work as well.
Edit: Bruno - i have the same behavior as you are seeing. I created a sample report with a string first parameter with no default value, and a string 2nd parameter with a default of =DateTime.Today.Year. When I have the one with the default as the 2nd parameter in the order, it shows up empty and disabled.
I was able to fix this problem 2 ways: first by adding a default of =String.Empty to my first parameter, and the second way was to just change the order of the parameters.
Not sure if this behavior is by design or a bug - but like you said, I hadn't noticed it either until today when you pointed it out in your question.
Try:
=Year(Now)
I'm not sure if this is what you need, but it worked for me. I used it to form a date string so I used =Year(Now).ToString().
SSRS does process the report parameters in order - order can be important if you have dependencies between your parameters.
From MSDN: "Parameter order is
important when you have cascading
parameters, or when you want to show
users the default value for one
parameter before they choose values
for other parameters."
So, it will always wait until you have a default value for your first parameter or you enter the first parameter's value, before it processes the next one, and so on.
http://msdn.microsoft.com/en-us/library/cc281392.aspx
I found the by making sure that ALL of my parameters had at least some default value, then you will not experience they greyed out datetime picker. So, every parameter before your datetime paremeter in order needs to have a (default) value or it will not work.
Def due to order of evaluation of parameters.
Simple workaround ; in the parameters tab you can change the order of the parameters - this will move the date pickers to the top of the list and are then enabled straight away, on my server at least.
Someone raised the issue of basing a date filter on a queried default value - if you do this, you will notice a very annoying knock-on effect of getting screen refresh any time the dates get changed, before you have a chance to requery the reports.