Date format in SSRS Expression - ssrs-expression

I am trying to change the date format for one of my field to dd/MM/yyyy but every time I used the below expression I get dd/MM/yyyy as the value in the cell instead of changing the format.
The data source that I am using is Teradata.
Expression used: =Format(FormatDateTime(Fields!DATE.Value, DateFormat.ShortDate),"dd/MM/yyyy")
Can some one help me with where am I going wrong.
Any help would be appreciated.

The FormatDateTime function returns a string instead of a date. When the FORMAT function tries to format it, it doesn't find a date field so it returns the characters in the format.
If your field is a date, you should be able to format the field without conversion:
=Format(Fields!DATE.Value,"dd/MM/yyyy")
If it does need to be converted first, try using the CDATE function:
=Format(CDATE(Fields!DATE.Value),"dd/MM/yyyy")

Related

How to add 13min's time in Time Field(not date time field) Crystal reports

I tried using Dateadd('n',13,{fieldname}).
but it throws an error not a valid date time field cause it is time field.
is there any way to convert it to datetime and add the value and revert it into time field?
Thanks.
Try this formula:
DateAdd('n',13,DateTime(CurrentDate, {fieldname}))
The DateTime(date, time) function will create a DateTime value that works in the DateAdd() function. This will only work if the {fieldname} is a Time data type though.
If {fieldname} is a string, you will need to convert it to a Time data type first using the Time(time) function.
The formula I suggested above will append your time value to today's date. You will then need to format the DateTime value it returns to only display the time value. This can be done by right clicking the field in your crystal report and clicking Format Field and setting the Style on the Date and Time tab.

Teradata character to date conversion

I have a string associated with date in ‘Teradata’ tables
Var1=09OCT2017-EMRT
I need to extract the date from the above string in ‘mm/dd/yyyy’ format
I tried the following
Cast(cast(substr(var1,1,9) as char(20)) as date format ‘mm/dd/yyyy’) as date
I am getting error as ‘invalid date supplied for var1’
I would appreciate your help
You need to apply a format matching the input string:
To_Date(Substr(var1,1,9), 'ddmonyyyy')
returns a DATE.
If you want to cast it back to a string:
To_Char(To_Date(Substr(var1,1,9), 'ddmonyyyy'), 'mm/dd/yyyy')

Changing Date Informats in SAS using the Query Builder

I want to change a date format in SAS to another date informat using the query builder.
I thought it should be as simple as:
INPUT(t1.In_date, MMDDYY10.)
But this returns the following error:
ERROR: INPUT function requires a character argument.
So I played about with it & tried a few things for example:
INPUT("t1.In_date", MMDDYY10.)
This doesn't create an error message but only produces blanks.
I've googled the error message but I can't see a way to solve this problem using the query builder.
The informat of t1.In_date is DATETIME18.
If anyone has any suggestion I would be grateful.
You've got a few problems here.
First, informat is the wrong terminology. Your date variables are dates (numbers) with formats; so, you want to change their format. informat is converting a text string to a number; format is changing how a number (or text string) is displayed.
Second, you have a datetime. Datetimes are stored as the number of seconds from 1/1/1960, while Dates are the number of days. That means that they will be not compatible format-wise. You have to use datepart to convert a datetime to a date (basically, this means dividing by 86400).
So, what you want to do:
put(datepart(t1.in_date),mmddyy10.)

Convert yyyymmdd to date for record selection

I'm a Crystal newbie with limited experience at SQL commands.
Here's my problem.
My database stores dates in the yyyymmdd numeric format. I created a Date Range parameter field to allow the user to select a date range. When I try to add the {?Date Range} to the record selection I get an error message that says "A number range is required here", apparently because my {?Date Range} field is looking for a date and not a number. I believe what I have to do is convert my dates to a date format, but I don't know how to do that.
Could someone please tell me how to make this work?
Much appreciation, thanks
I don't have Crystal around to check the syntax , but generally you need to convert the daterange to numeric values and use theese values in your record selection formula
the TO value will be
tonumber(totext(Maximum({?ParameterDateRange}),'yyyyMMdd'))
the FROM value will be
tonumber(totext(Minimum ({?ParameterDateRange}),'yyyyMMdd'))
so the formula might be something like
{YourField} IN tonumber(totext(Minimum ({?DateRange}),'yyyyMMdd')) TO tonumber(totext(Maximum({?DateRange}),'yyyyMMdd'))
You can also use < and > instead of between
you can use CDate fucntion to convert numeric to Date.
CDate(ToNumber(Mid(ToText(20141231),1,4)),ToNumber(Mid(ToText(20141231),5,2)),ToNumber(Mid(ToText(20141231),7,2)))
Check the link for documentation
http://www-01.ibm.com/support/knowledgecenter/SS4JCV_7.5.5/com.businessobjects.integration.eclipse.designer.doc/html/topic728.html
Try:
{table.date} IN ToText(Minimum({?DateRange}),"yyyymmdd") TO ToText(Maximum({?DateRange}),"yyyymmdd")

Casting date in Talend Data Integration

In a data flow from one table to another, I would like to cast a date.
The date leaves the source table as a string in this format: "2009-01-05 00:00:00:000 + 01:00".
I tried to convert this to a date using a tConvertType, but that is not allowed apparently.
My second option is to cast this string to a date using a formula in a tMap component.
At the moment I tried these formulas:
- TalendDate.formatDate("yyyy-MM-dd",row3.rafw_dz_begi);
- TalendDate.formatDate("yyyy-MM-dd HH:mm:ss",row3.rafw_dz_begi);
- return TalendDate.formatDate("yyyy-MM-dd HH:mm:ss",row3.rafw_dz_begi);
None of these worked. When inserting the result into the target-table (MySQL, InnoDB) a receive the error message that the date is not valid. The format of the target field is a MySQL Date field.
How can I cast the date to the desired format?
Talend offers you a nice way of handling date formats.
You can easily change the date format in the Schema editor tab at the tMap window.
It works for both tMap input and output flows.
I've added a picture for a better illustration.
to cast this string to a date using a formula.... error message that
the date is not valid. The format of the target field is a MySQL Date
field.
What I understand from your question is, you want to insert a date into MySQL Date field.
But the method that you are using, returns the 'String' type.
TalendDate.formatDate(String pattern, Date date); //formats a date into Date/Time string
So in that case, if your field is of 'Date' type.
TalendDate.parseDate("yyyy-MM-dd", TalendDate.formatDate("yyyy-MM-dd",row3.rafw_dz_begi));