So I've got what could be a very silly question, but for some reason my 'problem' isn't working.
It's quite simple really. One of the fields in a SSRS tablix is a due date calculated by using the SQL function DateAdd:
=DateAdd(DateInterval.Day, (Int(Fields!TMinus.Value) * 7), Parameters!StartDate.Value)
Where TMinus is a negative integer simulating weeks and StartDate being the date the activity started.
I'm calculating the same thing in VB.NET using this formula to set up the DueDate of an activity in a row cell:
Dim intTMinus As Integer = CInt(dataItem.GetDataKeyValue("TMinus").ToString)
CType(dataItem.FindControl("RlblDue"), RadLabel).Text = CDate(DateAdd(DateInterval.Day, (intTMinus * 7), dtStartDate)).ToString
The problem is that the SSRS report shows a DIFFERENT date than the Grid, even though I've used hardcoded values to attempt to find the culprit in the report.
This calculation in the report:
=DateAdd(DateInterval.Day, (Int(-40) * 7), '12/09/2016')
Shows the date: 07/12/2015 in the Grid, but 3/4/2016 on the Report
Note DateAdd arguments data types have to be DateInterval, Double, and DateTime respectively. You are passing a string '12/09/2016' for the third argument but it requires a DateTime. By the way, strings in SSRS must be surrounded with double quotes.
After fix the expression, it should be like this:
=DateAdd(DateInterval.Day, (Int(-40) * 7), CDATE("2016-09-12"))
Which returns: 07/12/2015 as your Grid in VB.
Note CDATE("2016-09-12") converts the date string in a DateTime value.
Check your parameter is set to Date/Time type.
REFERENCE
Let me know if this helps.
Related
I am trying to extract data based on a date condition connecting to SQL from R.
My database connection is from Impala.
Below is my sample code.
dbGetQuery(src,"SELECT * FROM sample WHERE eventdate BETWEEN '2017-01-31' AND DATEADD(m,1,'2017-01-31')")
I get below error while trying to query.
Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
Unable to retrieve JDBC result set for select * from sample where
eventdate between '2017-01-31' and dateadd(m,1,'2017-01-31') ([Cloudera]
[ImpalaJDBCDriver](500051) ERROR processing query/statement. Error Code: 0,
SQL state: TStatus(statusCode:ERROR_STATUS, sqlState:HY000,
errorMessage:AnalysisException: Could not resolve column/field reference: 'm'
), Query: select * from sample where eventdate between '2017-01-31' and dateadd(m,1,'2017-01-31').)
Instead of using DATEADD if I hard code between two dates I get the result e.g.
dbGetQuery(src,"SELECT * FROM sample WHERE eventdate BETWEEN '2017-01-31' AND '2017-02-28' LIMIT 5")
I get the result for above code but I want to use DATEADD in my code because I have multiple date conditions which I am doing using a loop function.
Any help regarding this please.
The problem is the format of your literal date string ('2017-01-31'). SQL Server, when passed a literal string for date for DATEADD will implicitly convert the value to a datetime. datetime will read the string in the format yyyy-dd-MM, translating the value to 20173101; you can see the problem there (there aren't 31 months in the year).
If you're using a literal string to pass a date(time) then use either the format yyyyMMdd or yyyy-MM-ddThh:mm:ss.sssssss as both are unambiguous regardless language and datatype.
So, for your value that would be:
WHERE eventdate BETWEEN '20170131' AND DATEADD(m,1,'20170131')
On a different note, are you really looking for rows between 20170131 and 20170228, inclusive of those dates (assuming eventdate is a date)?
remove time from your DATEADD function by using Convert function.
dbGetQuery(src,"SELECT * FROM sample WHERE eventdate BETWEEN '2017-01-31' AND convert(varchar,DATEADD(month, 1, '2017/08/25'),23)")
I am desiging dataentryform in access . I made tables and the datatye of one field is Date/time but in property field in format I put mm.\yyyy to get month and year . how should I define input mask for it? I want to see --.----
when I enter data in form I can see calender beside this field but I have to choose day as well I dont want to choose day however the day that I chose doesnt save in table but I have to choose day aw well.
more explaination: I have 2 fields that should define as mm.yyyy .one field is (start of project example 01.2010) and the next field is end of project which also has the same format mm.yyyy (03.2015).
and later I want to get a query which shows duration of project ( end of project - start of project) . so I should also do calculation according to my data.
but I dont know what kind of data type should I define in the table for these two fields. at first I tried Date/Time . but I couldnt find suitable format. then I changed it to short text and I entered 00.0000 in input mask.
what is the best solution because I have to calculate duration of project according to these two fields later? (in queries)
There are many ways around this. One is simply to allow the user to type freely in an unbound textbox, then validate/correct before updating.
Another is to have two/three juxtaposed textboxes for year-month(-day), then build the date value with DateSerial(y, m, d).
in VBA, mm/yyyy alone can never form a date value, so must silently add a day somehow.
Input masks should be avoided as they are a prime hate object for users.
If you insist, you can get an idea how to handle this from my article:
Entering ISO formatted date with input mask and full validation in Microsoft Access
It assumes the ISO sequence because year-month determines the possible day values.
Addendum:
Though decimal months is not an exact measure due to the varying day counts of the months, you will get pretty close with this function:
Public Function DecimalMonths( _
ByVal Date1 As Date, _
ByVal Date2 As Date) _
As Double
Dim Part1 As Double
Dim Part2 As Double
Dim Months As Double
Dim Days1 As Integer
Dim Days2 As Integer
Days1 = Day(DateSerial(Year(Date1), Month(Date1) + 1, 0))
Days2 = Day(DateSerial(Year(Date2), Month(Date2) + 1, 0))
Months = DateDiff("m", Date1, Date2)
Part1 = (Day(Date1) - 1) / Days1
Part2 = (Day(Date2) - 1) / Days2
Months = Months - Part1 + Part2
DecimalMonths = Months
End Function
Please note, that the count from 2017-04-15 to 2017-06-01 is 1.53
while it would be 1.5 from 2017-04-16 to 2017-06-01.
What is wrong with my code:
ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= 2016-12-14');
This runs, but deletes ALL the rows in STLac for RegN, not just the rows with BegDate on or after 2016-12-14.
Originally I had:
ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= :myDdate,[myDate]);
which has the advantage I hoped of not being particular to the date format. So I tried the literal date should in the format SQLite likes. Either way I get all rows deleted, not just those on or after the specified date.
Scott S.
Try double quote while putting date. As any value must be provided in between quotes until and unless that column is not int
ExecSql('DELETE FROM STLac WHERE RegN=99 AND BegDate>= "2016-12-14"');
SQLite does not have datetime format as such, so you have to figure out how date is actually represented in the table and change your query to provide the same format. First execute the "select" statement in some kind of management tool,
select * from STLac where RegN = 99 and BegDate >= '2016-12-14' --(or '2016.12.04' or something else)
which displays the result in the grid; when you see the expected rows, change it to "delete" query and copy into your Delphi program.
I´m new to MDX and I have a simple question. I work with the TFS Cube it is named as Team System. My problem:
I have an IIF expression where I want to check additional my expression with an AND operator. There I want to compare two DateTime objects. The report should only show me the data from the actual date. Here my code:
IIF(ISEMPTY(SUM(YTD(
[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember),
[Measures].[EffectivelyValue]))
AND[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember < Now()
, [Measures].[EffectivelyValue]
, SUM(YTD(
[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember),
[Measures].[EffectivelyValue]) )
Planned Week is a self created field which has the DateTime datatype. The Now() function has also a DateTime datatype so the comparision should be right but it happens nothing.
Thanking you in anticipation
Eugen
Hierarchy members in MDX have a data type of 'member', and do not have a 'primitive' data type like datetime, string, or integer. Only member properties have 'primitive' data types. You could either define a property like datetime of your week attribute. Assuming you are SQL Server Analysis Services, this would be done via relationships.
Or you could use string operations to extract the date information from the UniqueName property which avoids having to change the cube. The UniqueName contains the data that you defined as the key in your cube design. Assuming your week hierarchy members have a key from which you can extract something like 20130820 for August 20, 3013 via string functions (I just will use Mid(, 30, 8) as an example below), you could do something like
CLng(Mid([Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName, 30, 8))
<
CLng(Format(Now(), "yyyymmdd"))
You will have to check what exactly the CurrentMember.UniqueName shows in your cube to adapt the above code.
And finally, you could of course also use string methods to extract the relevant parts from the UniqueName and then the CDate function on that to compare to an unchanged Now(), i. e. do all operations on the left side of the <.
Hello thank you very much for you answer. I tried:
Mid([Work Item].[xxxx_PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName,58,10)
shows e.g. 2013-07-21, 2013-07-28 (it shows the week endings)
so I tried this:
AND CLng(Mid([Work Item].[xxxx_PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName,58,10))
<CLng(Format(Now(), "yyyy-mm-dd"))
But it happens nothing. If I execute it in a single way it shows everywhere "true". But I have datasets with dates which are e.g. > 2013-08-23. So there should be false values too.
EDIT: OK I solved the problem. The
Format(Now(), "yyyy-mm-dd")
must be
Format(Now(), "yyyy-MM-dd")
I'm trying to do a query like this on a table with a DATETIME column.
SELECT * FROM table WHERE the_date =
2011-03-06T15:53:34.890-05:00
I have the following as an string input from an external source:
2011-03-06T15:53:34.890-05:00
I need to perform a query on my database table and extract the row which contains this same date. In my database it gets stored as a DATETIME and looks like the following:
2011-03-06 15:53:34.89
I can probably manipulate the outside input slightly ( like strip off the -5:00 ). But I can't figure out how to do a simple select with the datetime column.
I found the convert function, and style 123 seems to match my needs but I can't get it to work. Here is the link to reference about style 123
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.blocks/html/blocks/blocks125.htm
I think that convert's slightly wrongly documented in that version of the docs.
Because this format always has century I think you only need use 23. Normally the 100 range for convert adds the century to the year format.
That format only goes down to seconds what's more.
If you want more you'll need to past together 2 x converts. That is, past a ymd part onto a convert(varchar, datetime-column, 14) and compare with your trimmed string. milliseconds comparison is likely to be a problem depending on where you got your big time string though because the Sybase binary stored form has a granularity of 300ms I think, so if your source string is from somewhere else it's not likely to compare. In other words - strip the milliseconds and compare as strings.
So maybe:
SELECT * FROM table WHERE convert(varchar,the_date,23) =
'2011-03-06T15:53:34'
But the convert on the column would prevent the use of an index, if that's a problem.
If you compare as datetimes then the convert is on the rhs - but you have to know what your milliseconds are in the_date. Then an index can be used.