The difference in strings in Tableau - tableau-api

I am using Tableau Server version 10.4.3
I have a dimension rTime which has string value. the entries in rTime is of like this
May 10, 2019 8:59:56.303 PM UTC
I want to check whether the rTime is today or not. I cannot use DateParse since my server doesn't have this functionality.
I created a calculated field CheckrTime with below content :
STR(LEFT(SPLIT([rTime],':',1),LEN(SPLIT([rTime],':',1))-2))
When I am dragging CheckrTime into workspace area, the output is coming in below format which is what I wanted :
May 10, 2019
When I am checking ISDATE("May 10, 2019") (a normal string), it is outputting TRUE as expected but when I am checking ISDATE(CheckrTime) it is outputting FALSE . Why?
The reason I am checking above thing is I am looking to use DATEDIFF function of tableau in this way:
DATEDIFF('day', DATE(CheckrTime), TODAY()) == 0
NOTE
If someone is wondering ,I have taken care of the level of granularity.
If you have a better solution then the one I am following, please do tell me.

This is working for me. I would expect May 10 <> May 16 (today) and therefore return false. However, when I change your example to today's date it does in fact come back as true.
You could also try this formula for the date LEFT([rTime],FINDNTH([rTime],' ',3)). It is slightly less complicated but will give you the same answer.

Calculated field (date type) depends the locale used which defines date format. Are you able to use Date function?
In Tableau website there is a example using english locale
For string 06May2017
DATE (LEFT([Original Date], 2) + "/" + MID([Original Date],3,3) + "/" + RIGHT([Original Date],4))
Above mentioned highligts / character between digits which is depending on locale

Related

Google Sheets - DATE format not working on imported Date in TEXT format

I text based .csv file with a semicolon separated data set which contains date values that look like this
22.07.2020
22.07.2020
17.07.2020
09.07.2020
30.06.2020
When I go to Format>number> I see the Google sheets has automatic set.
In this state I cannot use and formulas with this data.
I go to Format>number> and set this to date but formulas still do not see the actual date value and continue to display an error
Can someone share how I can quickly activate the values of this array so formulas will work against them?
I would be super thankful
Where the date are in column A, starting in cell A1, this formula will convert to DATE as a number, after which you apply formatting to Short Date style.
=ARRAYFORMULA(IF(A1:A="",,DATE(RIGHT(A1:A,4),MID(A1:A,4,2),LEFT(A1:A,2))))
Hopefully(!) the dates stay as text, otherwise Google Sheets would sometimes detect MM/dd/yyyy instead of dd/MM/yyyy, and you won't be able to distinguish between July 9th and September 7th in your example.
Solution #1
If your locale is for instance FR, you can then apply
=arrayformula(if(A1:A="";;value(A1:A)))
solution#2
you can try/adapt
function importCsvFromIdv1() {
var id = 'the id of the csv file';
var csv = DriveApp.getFileById(id).getBlob().getDataAsString();
var csvData = Utilities.parseCsv(csv);
csvData.forEach(function(row){
date = row[0]
row[0] = date.substring(6,10)+'-'+date.substring(3,5)+'-'+date.substring(0,2)
})
var f = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
f.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
First thanks to those that suggested a fix. I am not really a programmer and get cold sweats when I see suggesting of running scripts to solve simple problems. Sorry guys.
So the (non programmer) solution with the dates was to do a find/replace (CTRL + H) and replace all the (.)dots with (/)slashes, then to make sure the column is formatted as a date, then Google finally understands it as a date.
With the accounting values as well, I had to do the same find/replace to remove all the ' between thousands, then google woke up and understood them as numbers.
I am significantly underwhelmed by this from Google. They are getting too fat and lazy. They need some competition.

spss-modeler date difference getting negative results

First of all, I'm new to SPSS modeler, sorry if my question sound too obvious for experts, but what I'm trying is to calculate the date difference between two date values ( arrive_Date , Depart_Date ) in (Hours), I used this function time_hours_difference , this function works okay if the Arrive_Date and depart_date are the same day, but if the days are different, the date difference is in negative value, I searched and enabled this option: Rollover days/mins in stream properties, but the problem remains the same.
I hope you can help me with this beginner question.
Thanks
Hope its not too late. You are getting negative values because time_hours_difference extract only the time from the two specified timestamps and computes the difference out of it. It doesn't take the date values into account.
For example:
time_hours_difference('2012-08-02 14:10:50,2012-08-05 13:36:26)
Output:
-0.573
Remember, here time_in_hours('0130') under time format 'HHMM' evaluates to 1.5.
Here is my solution: in order to take days into account, first extract date_days_difference and multiply it with 24 to bring it in Hours and then sum it up with the time difference using time_hours_difference.
date_days_difference(arrive_Date,Depart_Date)*24 +
time_hours_difference(arrive_Date,(to_string(datetime_date(arrive_Date)) >< " 23:59:00")) +
time_hours_difference((to_string(datetime_date(Depart_Date)) >< " 00:00:00"),Depart_Date)

In Julia, if date is 96, how can I make it 1996 in DateTime?

I have an array with strings of dates. The format is "2/27/16 3:47" so "m-d-y H:M". However, DateTime parses this as 0016-27-02T03:47:00. I would like to have the output be: 2016-27-2T03:47:00.
My code is:
map(date-> DateTime(date, "mm/dd/yy HH:MM"), datsub[:date])
Side question: The output type becomes Any. Is this the correct type or should it be DateTime or something similar?
As #akrun mentioned, you should add the year yourself:
Dates.Year(2000) + DateTime(date, "m/d/y H:M")
This is more explicit about exactly what is happening. Otherwise Dates would have to guess what exactly something like 97 means: 1997 or 2097, or actually year [00]97?
It's possible that you might want to come up with a reasonable cutoff for what year to add. You can try the following:
expandyear(date::DateTime) = date + (Dates.year(date) < 25 ? Dates.Year(2000) : Dates.Year(1900))
with whatever cutoff you think makes sense.
The issue with return types with map is a known problem that has been fixed in the latest v0.5 nightlies. Julia v0.5 is likely to be released in the near future, perhaps within several months.

How to check if date equals date of datetime property only using query parameters

I have a DateTime property.
I want to check if a date is equal to the date in my property and it has to be done purely in the url query parameters available in OData v4.
This doesn't work :(
GET ~/odata/foo$filter=date(myProperty) eq date(1980-01-01)
Yes I can use greater then or equal but that's is already working as intended. It's equal and not equal that's the problem.
From ABNF rules, Date value is a value with format:
dateValue = year "-" month "-" day
So, I think you shouldn't add date prefix. That's:
GET ~/odata/foo$filter=date(myProperty) eq 1980-01-01
Here's some test cases provided by ODataTeam:
https://github.com/OData/WebApi/blob/master/OData/test/E2ETest/WebStack.QA.Test.OData/DateAndTimeOfDay/DateAndTimeOfDayTest.cs#L169-L171
and
https://github.com/OData/WebApi/blob/master/OData/test/E2ETest/WebStack.QA.Test.OData/DateAndTimeOfDay/DateAndTimeOfDayTest.cs#L208-L212
Besides, there's a simple tutorial you can refer to:
http://odata.github.io/WebApi/#04-04-date-and-timeofday-support
Thanks. Hope it can help.

DateAdd() returns faulty Date in SQL Server Reporting Services

I have a report that takes a date as a parameter.
If I use =Parameters!Date.Value, the report runs fine.
However, if I use =DateAdd("d", 1, Parameters!Date.Value), the report is left blank, even though the formats are exactly the same:. (Note: it simply cannot run. It's not that there are no values to return as the field names don't return either.)
I have also tried =DateAdd(DateInterval.Date, 1, Parameters!Date.Value)
=DateAdd("d", 1, Parameters!Date.Value)
=DateValue(FormatDateTime(DateAdd("d", 1, Parameters!Date.Value), DateFormat.ShortDate )) and many variations thereof but I can't seem to crack it!
Update
If I use DateInterval.Month instead of DateInterval.Day then the date is still incremented as desired (12/22/2010) but the table shows up! Interesting how my local settings are dd-mm-yyyy and these dates are mm-dd-yyyy.
Try changing the locale of the report to EN-GB (I'm assuming you're in the UK), as the report might be getting confused between different date formats.