How do I format a date to put it in a factory_girl_rails factory eg:
Factory.define(:profile) do |t|
t.length 110
t.shipdate 1993-04-06
end
If it matters, I'm using postgresql and factory_girl_rails 1.0. The error I've been getting is ActiveRecord::StatementInvalid: PGError: ERROR: invalid input syntax for type date: "1982" The rails version is 3.1
You're missing the quotes around your date string:
Factory.define(:profile) do |t|
t.length 110
t.shipdate '1993-04-06'
end
1993 minus 4 is 1989, 1989 minus 6 is 1983. Are you sure you copied the error message correctly?
The error message tells us, that you tried to write the string '1982' to a date field, which is obviously not valid. A date needs a month and a day, too.
If you keep having input of that sort, you could process it with to_date(), which can make sense of it:
SELECT to_date('1982', 'YYYY-MM-DD')
Result:
1982-01-01
There are a couple of settings that influence processing of date/time values, most importantly DateStyle. An explicit cast with to_date() works independently, though.
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 a client in Germany using an SSRS report and the date parameter is showing "OKT" instead we need it to be "OCT" for october
Is there a setting to make sure GETDATE() is already converted or will a convert function work?
here is my error:
library!ReportServer_0-45!1554!10/15/2018-10:23:17:: i INFO:
RenderForNewSession('/Finance/MC Dashboard')
processing!ReportServer_0-45!10bc!10/15/2018-10:23:17:: e ERROR:
Throwing
Microsoft.ReportingServices.ReportProcessing.ReportProcessingException:
,
Microsoft.ReportingServices.ReportProcessing.ReportProcessingException:
Query execution failed for dataset 'JournalEntries'. --->
Microsoft.AnalysisServices.AdomdClient.AdomdErrorResponseException:
Query (5, 39) Cannot convert value 'Okt 14, 2018' of type Text to type
Date. at
Microsoft.AnalysisServices.AdomdClient.AdomdConnection.XmlaClientProvider.Microsoft.AnalysisServices.AdomdClient.IExecuteProvider.ExecuteTabular(CommandBehavior
behavior, ICommandContentProvider contentProvider,
AdomdPropertyCollection commandProperties, IDataParameterCollection
parameters)
Since the GetDate is coming through in German from the server, then the SQL CONVERT function should also use German to convert it to a date.
CONVERT(DATETIME, GETDATE(), 106)
If you do get an error, you might need to set the language first (SET Language German;) - though that would be wonky that one SQL function would work in German but the other doesn't.
just capture the data first in a text box and check its format. Depending on how it looks you can worse case convert this receive input param to internal varchar and then just get the date part out. i.e.
declare #internal_param as varchar(15);
set #internal_param = #Input_dateParam --your variable name here
--select logic here
I have a string input format of i.e
'Thu, 30 Nov, 2017'
I need to transform this into a more Oracle database friendly Date type format of something like '11-30-2017' or '11/30/2017'. I started in the path of
Convert(' ','-',Convert(',','',DSLink.InputDate[5]))
which should return a string of: 30-Nov-2017
However I'm stuck on dynamically parsing the 'Nov' month part. Any clever ideas?
also I don't think this will work:
StringToDate(Convert(' ','-',Convert(',','',DSLink.InputDate[5])),"%dd-%mm-%yyyy")
as the function is looking for a numeric type on the month field?
I have started using DateCompare() function in one of my pages. I run into few problems.
First thing, the two date arguments that I use in my function sometimes can be empty. My argument Date 1 is coming from query and there is some situation when there is no records. In that case DateCompare function was throwing an error since can accept only date values.
Second problem is when I tried to check if my Date1 is greater than Date2, using "d" for days difference. I used 1 that should indicate that Date1 is greater, but my logic still processed when Date1 is less than or equal to Date2.
I'm wondering if this is the best way to compare dates in ColdFusion and if there is better way to approach this problem? Here is my example:
<!--- This arguments user picks on the screen with date picker --->
<!--- Example startDt value passed to server side: 03/23/2017 --->
<cfargument name="startDt" type="string" required="yes">
<!--- This argument is coming from the query and sometimes can be blank --->
<!--- Example curBegDt value passed to server side: 03/30/2017 --->
<cfargument name="currentBeginDt" type="string" required="no" default="">
<cfif DateCompare(trim(arguments.currentBeginDt),trim(arguments.startDt),"d") EQ 1>
Do INSERT/UPDATE SQL Query
</cfif>
As you can see from the code above my INSERT/UPDATE should execute only if currentBeginDt is greater than startDt but also in the case when currentBeginDt is blank/empty. If anyone have suggestion how to solve this problem please let me know.
The key thing to understand about that function is it's called DateCompare, not StringCompare ;-) It is designed to compare date objects, not strings or empty strings.
Yes, CF lets you be lazy and pass in date strings. However, CF still needs to convert those strings into date objects before it can compare them. So you are leaving the interpretation of those string entirely up to CF. Depending on the input, it may work .. or you may get some unexpected/wrong/confusing results.
The best way to ensure consistent results is to:
Validate the input to ensure it actually IS a valid date. If not, abort or apply appropriate error handling.
Otherwise, convert the input string into a date object using functions like ParseDateTime() or LSParseDateTime(), both of which support a "format" argument for parsing as of CF10. For CF9 and earlier, you will need to roll-your-own.
After you are sure you have valid date objects, pass them into DateCompare()
my logic still proccessed when date 1 is equal or less than date
Most likely because you are using strings, and CF is interpreting those strings differently than you are expecting. We would need to see an example of the actual values to provide more specifics.
First:
<cfif NOT isDate(arguments.currentBeginDt)
OR DateCompare(trim(arguments.currentBeginDt),trim(arguments.startDt),"d") EQ 1>
...will do the insert/update query if date1 is after date2 OR date1 is not a date.
If date1 and date2 are truly equal, then the result of DateCompare should be 0. If you're getting 1 and think it's wrong, then check the dates, because they're probably not what you think they are.
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.