I want to get current date +/- some hours.
According to docummentation, one of those should work:
date_sub(now(), interval 1 hour)
date_sub(current_time(), interval 1 hour)
but it doesn't. I use Makumba version is 0.8.2.5.1
Am I doing something wrong?
Indeed, these functions work only in Makumba >= 0.9 (and in some versions <= 0.7)
A workaround in 0.8 is to do the date programmatically via JSP tags, e.g.:
<jsp:useBean class="java.util.Date" id="oneHourAgo" />
<jsp:setProperty name="oneHourAgo" property="hours" value="${oneHourAgo.hours - 1}" />
and then use the variable inOneHour (which is in the pageContext) as a named parameter in your query, e.g.:
<mak:list from="company.Company c" where="c.TS_create >= $oneHourAgo">
....
</mak:list>
Unfortunately in the versions prior to 0.9 the date_sub and date_add functions don't get parsed correctly so they don't work properly. (it should actually be removed from the documentation)
In the version 0.9+ you'll have new functions dateAdd and dateSub and for your case you would do:
dateSub(now(),1,'hour')
and that should work.
Related
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
i have to dates: xs:date(current-date()) and something like this 2017-11-01T09:17:00Z.
I need to get difference in minutes.
My idea is with minutes-from-duration() function, but i don't know how convert the dates to right input
You can simply substract two dates or dateTimes in XSLT/XPath 2 or later with e.g. current-dateTime() - xs:dateTime('2017-11-01T09:17:00Z') to get a duration, then you can use your function or other operations like e.g. (current-dateTime() - xs:dateTime('2017-11-01T09:17:00Z')) div xs:dayTimeDuration('PT1M') which would divide the duration by 1min.
For all of my dates, Format subtracts exactly 4 hours from the hour field.
Here is an example for clarification:
When I retrieve a date in Microsoft SQL Server Management Studio, the date column returns dates in this format: 2014-10-30 11:19:02.733.
When I execute the same command using sql and display the value in a gridpanel, it is displayed in this format: 2014-10-30T11:19:02.733.
However, When I try to use Format="yyyy-M-d, HH:mm", the date is returned as 2014-10-30 07:19:02.
For easier comparison, this is what the difference is:
2014-10-30 11:19:02.733
2014-10-30T11:19:02.733
2014-10-30 07:19:02
What could cause the removal of exactly 4 hours every single time?
Thank you.
Additional code:
<ext:DateColumn ID="Column6" runat="server" Text="When" DataIndex="time" Flex="1" Format="yyyy-M-d, HH:mm" />
For anyone who stumbles upon this question in the future:
I found the solution, based on Julien's guess!
I changed the timezone on my pc and it consequentially changed the value again.
It turns out, that the way around this is is to add a type to the modelField. It would look something like this <ext:ModelField Name="time" Type="Date" />.
For some reason, this prevents the client-side time-zone override.
I am doing a manual query to my postgresql database (using OrmLiteReadConnectionExtensions.SqlList<T>) that has a TimeSpan argument.
SericeStack.Ormlite is converting TimeSpan to ::time instead of ::interval as I would expect it.
More specifically: TimeSpan.FromDays(3) is converted to ((E'00:00:00.000000')::time)(taken form pg logs).
Is there a work around for this?
My current work-around is to use the C# string.Format for this problematic parameter instead of the safe and recommended™ #paramname supported by SqlList<T>.
This could be considered dangerous, but since the parameter is a double, I'm probably Okay.
The relevant part of the string is:
string.Format(CultureInfo.InvariantCulture, "RESTOFTHEQUERY ('{0:0.####} seconds'::interval) RESTOFTHEQUERY", timespan.TotalSeconds);
Don't forget to use CultureInfo.InvariantCulture.
For what it's worth, you can just cast a time value to interval. Demo
SELECT now()::time::interval
So append ::interval in your manual query and you should be fine - except for intervals > 24 hours of course.
Pulling my hair out again...
I need to calculate the difference between two dates in days. I'm doing this:
<cfset d = DateDiff("d", Dateformat( active_apps.app_base_coupon_start, "dd.mm.yyyy"), Dateformat( variables.useDate, "dd.mm.yyyy") )>
With active_apps.app_base_coupon_start = 27.07.2012 and variables.useDate = today = 02.10.2012.
I dumped both values, they are OK. However the dateDiff returns -168 when I was looking for (4 days in July, 31 in August, 30 in September, 2 in October) 67 days.
Question:
Can someone prevent me from losing my remaining hair and tell me what I'm doing wrong here or if there is an easier way to get the difference in days?
EDIT:
Ok, it also works like this:
<cfif DateAdd("d", active_apps.app_grace_time, Dateformat( active_apps.app_base_coupon_start, "dd.mm.yyyy") ) GT now()>
<cfdump output="e:\s\page\t\dump.txt" label="catch" var="YUP">
<cfelse>
<cfdump output="e:\s\page\t\dump.txt" label="catch" var="NOPE">
</cfif>
but I would still like to know, why dateDiff is returning strange values.
DateDiff("datepart", date1, date2) takes a datepart and two date objects as arguments.
DateFormat() as Adam Cameron already said returns a string and not a date object.
ColdFusion is trying to read "27.07.2012" and "02.10.2012" as date objects by trying to apply some known date formats. That's why "02.10.2012" is interpreted as "Feb 10 2012".
I wouldn't let ColdFusion guess the dateformat of your string. Instead you should create date objects by using CreateDate(year, month, day).
now() is also a ColdFusion date object.
First things first, dateAdd() takes DATES as arguments, not dateFormat()-ed strings. dateFormat() is for output, not for calculations.
You need to understand that just because "02.10.2012" looks like a date to you (and to me), it's not a date as far as the computer is concerned: it's a string.
Never use strings for date calculations.
In your case, CF is valiantly trying to work out what "02.10.2012" might mean as a date, and deciding it's "mm.dd.yyyy" format, which is Feb 10, whereas you mean Oct 2.
You're using an ambiguous date format. Change the DateFormat to international date format (ISO 8601) whenever you make date calculations and things will be a bit more predictable. Note that CF doesn't support every variant of the ISO format, but for the most part you just need yyyy-mm-dd which is supported.
<cfset d = DateDiff("d", Dateformat( active_apps.app_base_coupon_start, "yyyy-mm-dd"), Dateformat( variables.useDate, "yyyy-mm-dd") )>