I am using an ADF application. I have stored the date value in long format in my database.
I am using the input date format.
my coding is given bellow
<af:inputDate label="Label 1" id="id1" value="#{pageFlowScope.TestBean.date}"/>
I want to convert the long value to date format using El expression if it's possible to convert long to date using all expression?
Thanks in advance
You are probably looking for the af:convertDateTime component.
Or you could set the date format directly in your VO (if your attribute is mapped to Timestamp).
In the back bean, you should have a Date variable ready already, you could use new Date(your_long_value_variable) to create a Date object. Then bind the date object with the value of your inputText/outputText, then use the af:convertDateTime to convert the format. For example:
<af:outputText value="#{your_date_variable}"
id="example1">
<af:convertDateTime type="both"
timeZone="GMT"/>
</af:outputText>
The type attribute specifies what contents the string value will be formatted to include, or parsed. Valid values are "date", "time", and "both". Default value is "date".
And timezone attribute is in which timezone to interpret any time information in the date string. And you can also edit the pattern attribute to decide the date format.
You could also modify the "pattern" attribute to change the format.
Plus, http://docs.oracle.com/cd/E15051_01/apirefs.1111/e12419/tagdoc/af_convertDateTime.html is the link for the af:convertDateTime.
Related
I have a String field in a Dataset in (mmddyyyy) format.
I am trying to convert it into a Date field in SSRS.
I already tried using the below command but I am getting error.
CDate(Fields!LocalTXNDate.Value)
Can anyone please suggest.
While Larnu is correct, the way to do it is to correct the database, sometimes we lowly report makers have no say in making these changes - much less getting a DBA to do it in a reasonable amount of time.
If you can't change the data to be correct, the easiest way to convert and use the field as a date is to add a Calculated Field to the Dataset. Open the dataset properties, click on the Fields tab, Add a Calculated field.
For the Expression, use string functions to parse the field into a generic date format and then CDATE to convert to a date type. Then use the new field for dates. You could also use this in your text box if it's not being reused but it's easier to manipulate the Calculated field.
=CDATE(
RIGHT(Fields!LocalTXNDate.Value, 4) & "-" &
LEFT(Fields!LocalTXNDate.Value, 2) & "-" &
MID(Fields!LocalTXNDate.Value, 3, 2)
)
The problem here isn't SSRS but your data, and that you are using a string based data type to store the data. You need to fix the problem at the source, not at the report level.
The string format you have chosen, MMddyyyy isn't a format that is recognised by default in any of the languages in SQL Server, nor if you explicitly use SET DATEFORMAT, nor does it appear as a style. SET DATEFORMAT MDY; SELECT CONVERT(date,'11172022'); will fail. Therefore you'll need to first do some string manipulation on the data first to be an unambiguous format (yyyyMMdd):
UPDATE YT
SET YourDateColumn = CONVERT(varchar(8),V.DateValue,112)
FROM dbo.YourTable YT
CROSS APPLY (VALUES(TRY_CONVERT(date,CONCAT(RIGHT(YT.YourDateColumn,4),LEFT(YT.YourDateColumn,4)))))V(DateValue);
For any bad values you have, such as '17112022' this will UPDATE the value to NULL; as such you may want to create a new column for the new value, or perhaps a new column to store the value of dates that couldn't be converted.
After you've changed the value to an unambiguous format, then you can ALTER the column:
ALTER TABLe dbo.YourTable ALTER COLUMN YourDateColumn date NULL;
Note that if you have any constraints, you will need to DROP those first, and then reCREATE them afterwards.
Now that the data type of the column is correct, you need not do anything in SSRS, as the data type is correct.
I have a dynamic field in SOLR that its value is stores as string
The value in it is a date string like:
"md_LocalStartTime": "2013-01-31T22:12:54.8000000+0000",
I want to get the max value for this
What wuery should I use to convert this to date and get the maximum?
Thanks
As a matter of fact, with this kind of date string representation lexical order is also date order, so ...sort=md_localStartTime%20DESC&rows=1&start=0
I'm trying to format the current date according to the generic "2012-09-04 10:20:12 AM" format but somehow the the "AM" part is always missing.
I'm using the expression "..." & Format(CDate(Now), "yyyy-MM-dd hh:mm:ss tt") to format the date and append it to some text. That emits the warning reproduced below but prints out the date correctly (except for the AM/PM designator).
[rsRuntimeErrorInExpression] The Value expression for the textrun
‘EmissionDate.Paragraphs[0].TextRuns[0]’ contains an error: Input string
was not in a correct format.
What am I doing wrong here?
Note: I'm aware of this SO post and SQL Server query backed solutions but I'd like to use the built-in functions as much as possible.
I found this article and maybe it can solve your problem. I know you are already using Format(CDate) but since you are using (Now), witch is a datetime variable, maybe you should use FormatDateTime() instead of Format().
Try this as well:
Instead of: Format(CDate(Now), "yyyy-MM-dd hh:mm:ss tt")
Use: Format(CDate(Now), "yyyy-MM-dd hh:mm:ss am/pm")
Link:Working with Dates in Reporting Services
As per my previous comment, the report's Language property was referencing a culture for which no AM/PM designator was defined. Changing it to en-US presented the AM/PM designator as expected.
Is there any way to check Date(like isDate function in TSQL) column in SSIS package derived column expression after extraction from Sourcefile before loading to target dtabase?
Thanks
there is no built in function but you can run a script task and use vb.net code to check if the column is a date and operate on it as you wish...
I had a similar issue. I had a date/time in a text file, but the field had a dash between the date and the time. I created a derived column to do a replace on the dash:
REPLACE([TimeField], "- ", "")
I then added a convert column to convert the field to a date. I chose to ignore errors. I then added another Derived Column to check if the converted field was NULL, indicating that it could not convert the value. If it was, I had it set to the current date.
There is a a data conversion task you can drop in. Then redirect the rows as needed, either failing the import entirely or redircting the rows that don't work.
Or you could try a conditional split wher eyou cast the field to a date data type and then send the failures along another path (either deleting the records or nulling out the field would be the common action.)
See also http://www.sqlis.com/sqlis/post/Expression-Date-Functions.aspx > "IsDate workaround" for a technique that can be adapted
You can check whether your variable has a date or not using a conditional statement like this:
testDateVariable?true:false
For example, if date > 2 then it is true (and put the date, or format the date as you wish). If it is false, put null (you replace true with the date format and false with null).
All this is in a drived column in SSIS.
Specifically, I wish to get the date format in a pure (ISO) format:
YYYY-MM-DD HH:mm:ss
I'm looking for a SET command or something that I can use.
I do not wish to rely on the culture setting of the server.
Note: I'm interested in the string format in which dates are returned, not entered.
To change the default format you need to add a new language (sp_addlanguage), set it's date format, then set the default language to it. More details can be found on this old technet article.
If you don't want to do that, then you can change it "per connection" using SET DATEFORMAT.
And if you don't want to do that, then you can use CONVERT to convert it to the relevent format string in each query.
Here's a handy article I found:
http://www.sqljunkies.ddj.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk
What you're looking for is:
CONVERT(datetime,'05/08/2004',120)
This will return a date in the format you're after yyyy-mm-dd hh:mi:ss(24h) format (ODBC canonical, not ISO).
the formatting of the datetime depends on the client. You can use the convert function to display it as a string in the format of your choice.