I have a table with a YearMonth column (201302) in it.
I created YearMonth a parameter.
Now I would like to write an expression in SSRS so that every time the report runs the date and month would look like this Feb-2013.
Could you please suggest me why following expression did not work.
Thanks
=CStr(Right(MonthName(Month(Parameters!NLR_YearMonth.Value)),3))
+ "-" +
Left(Year(Parameters!NLR_YearMonth.Value),4)
Try This:
=Format(DateValue(MonthName(Right(Parameters!NLR_YearMonth.Value, 2))
+ "," +
Left(Parameters!NLR_YearMonth.Value,4)), "Y")
The expression goes as follows:
Cutting the string to get the month.
Converting the mount to MountName
Creating a comma seperator between the month and the year
Cutting the string to get the year
Converting the returns string to Date object using the DateValue function
Formatting the Date to fits your needs
The results should be:
February, 2013
Related
The column is a nvachar(20).
select [shipment_posted_date_arch]
FROM [RxIntegrity].[dbo].[DiscrepancyReport_Receipts]
When I pull this, the date is in this format of 1200819 for that column. I need to convert to normal date.
This seemed to work:
cast(convert(nvarchar(20), (19000000 + CONVERT(int, shipment_posted_date_arch))) as date)
I have a report designed in iReport with an integer field and it is displaying like:
End date
20171022
20170906
20170903
but I need to show this field in date format like:
22/10/2017
06/09/2017
03/09/2017
The 20171022 value at DB means the 22 October of 2017 date
Is there any way to do this?
You can use below expression to achieve your desired result.
$F{column_name}.toString().substring(6,8) + "/" + $F{column_name}.toString().substring(4,6) + "/" + $F{column_name}.toString().substring(0,4)
You can handle the same inside your query. You just have to convert above expression as per your selected database.
I combine two columns; date and time. When I pass the date and time hot coded it works fine but when I pass it through a column it throws the error:
Unparseable date: "05/05/1992"
I already tried this:
MaterialCodeCSV.xdate == null ?
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", TalendDate.getDate("yyyy-MM-dd HH:mm:ss")) :
TalendDate.parseDateLocale("yyyy/mm/dd HH:mm:ss",MaterialCodeCSV.xdate.toString() + MaterialCodeCSV.xtime.toString(),"EN");
Java code in Talend:
Date handling can be a bit tricky if using wrong data types. I assume you want to fill a field which is a Date. There are several errors with this way:
MaterialCodeCSV.xdate == null ?
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", TalendDate.getDate("yyyy-MM-dd HH:mm:ss")) :
TalendDate.parseDateLocale("yyyy/mm/dd H:mm:ss",MaterialCodeCSV.xdate.toString()+ MaterialCodeCSV.xtime.toString(),"EN");
If MaterialCodeCSV.xdate == null you create a date and parse it again instantly? That seems unneccessary complex and inefficient. Change this to TalendDate.getCurrentDate()
Then if xdate is not null, you just concat xdate and xtime, use toString() and try to parse this. Again, this seems unneccesary complex. If I just assume now and xdate and xtime are already Date fields, you could write it as this: MaterialCodeCSV.xdate + MaterialCodeCSV.xtime.
If both are String fields, you have to make sure that xdate is formatted yyyy/MM/dd and xtime is HH:mm:ss. Then you could exclude .toString()
Also, if both are String fields, you have to add an additional space: MaterialCodeCSV.xdate + ' ' + MaterialCodeCSV.xtime
Additionally, in the first case you parse with yyyy-MM-dd HH:mm:ss. In the second case you parse with yyyy/mm/dd H:mm:ss. This reads "year/minute/day". Also there is only one hour digit, not allowing anything after 9:59:59 o'clock to be parsed. Correctly you should use yyyy/MM/dd HH:mm:ss.
So to conclude it should look like this (if I assume correctly and you are using correctly formatted String fields for xdate and xtime):
MaterialCodeCSV.xdate == null ?
TalendDate.getCurrentDate() :
TalendDate.parseDateLocale("yyyy/MM/dd HH:mm:ss", MaterialCodeCSV.xdate + ' ' + MaterialCodeCSV.xtime,"EN");
I am trying to use DatePart() within a MS Access select query to extract a month and year-- as a number-- from a date which is initially in a string form of
"YYYY-MM-DD HH:NN:SS.0000000"
The initial code written by someone else says:
DatePart("m", date)
DatePart("yyyy", date)
But this was causing a "Data Type, Mismatch in Criteria" error when the query ran, so I attempted to use Cdate() to convert the string to a date type.
DatePart("m", Cdate(date))
DatePart("yyyy", Cdate(date))
However this did not solve the problem. I am wondering if my initial date string is not in a form that Cdate() can convert, or if there is an easier way to extract a partial, numerical date from a date string such as mine.
I am prepared to elaborate much further on the situation in case this question is incomplete, but I did not wish get ahead of myself.
Those extra zeros would be a problem, to strip them, you could say
CDate(Mid(sdate, 1, InStr(sdate, ".") - 1))
Then
DatePart("m", CDate(Mid(sdate, 1, InStr(sdate, ".") - 1)))
However, you may find it more convenient to just refer to the appropriate part of the string:
aYr = Left(sdate,4)
aMnth = Mid(sdate,6,2)
You were right that the fractional seconds prevent CDate from accepting your string. And you could strip away the fractional seconds. But since you ultimately want the year and month, you can ignore all of the time components and just use the date part.
See whether this Immediate window session offers anything useful.
MyString = Format(Now(), "yyyy-mm-dd hh:nn:ss") & ".0000000"
? MyString
2013-02-14 23:38:09.0000000
' if date format is always yyyy-mm-dd,
' give CDate the first 10 characters
? CDate(Left(MyString, 10))
2/14/2013
' year
? DatePart("yyyy", CDate(Left(MyString, 10)))
2013
' or
? Year(Left(MyString, 10))
2013
' month
? DatePart("m", CDate(Left(MyString, 10)))
2
' or
? Month(CDate(Left(MyString, 10)))
2
' if date format can vary slightly, eg yyyy-m-d,
' give CDate everything before the first space
? CDate(Left(MyString, InStr(MyString, Chr(32)) -1))
2/14/2013
? Year(CDate(Left(MyString, InStr(MyString, Chr(32)) -1)))
2013
? Month(CDate(Left(MyString, InStr(MyString, Chr(32)) -1)))
2
You didn't mention what you will do with the year and date numbers after you get them. If you intend to join them together as a string, you could use Format().
? Format(Left(MyString, 10), "yyyymm")
201302
I tried parsing a string in a namedQuery, but it seems doesnt work. I have this code in my domain class:
searchBirthdaten{ q ->
def dates = Date.parse("yyyyy:MM:dd HH:mm:ss", "2011-9-21 00:00:00")
eq 'birthDate' , dates)
}
But I always got this error:
Unparseable date: "2011-9-21 00:00:00"
I really dont understand why this is happening. Any idea?
Your date input string has to be in the format you defined: yyyy:MM:dd HH:mm:ss (corrected)
So your 3 issues were:
You are using the "-" character to delimit you date for parsing but your format string is using ":"
You have 5 ys in your format string i.e. yyyyy:MM.... Which won't be valid for another 8 thousandish years ;)
You define your month format as MM but you are passing only '9', this will need to be '09' to match your fomat string.